ForestHub SDK 0.1.0
C++14 LLM SDK for PC and embedded platforms
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 ForestHub. All rights reserved.
3// For commercial licensing, visit https://github.com/ForestHubAI/fh-sdk
4
5#ifndef FORESTHUB_CORE_TYPES_HPP
6#define FORESTHUB_CORE_TYPES_HPP
7
10
11#include <memory>
12#include <string>
13#include <vector>
14
22
23namespace foresthub {
24namespace core {
25
26using json = nlohmann::json;
27
29using FileID = std::string;
30
33 std::string name;
34 json schema;
35 std::string description;
36};
37
41 std::shared_ptr<Input> input;
42 std::string system_prompt;
45 std::vector<std::shared_ptr<Tool>> tools;
46 std::vector<FileID> file_ids;
47 std::vector<FileID> image_ids;
48 std::vector<std::string> image_urls;
50
52 ChatRequest() = default;
53
57 ChatRequest(ModelID model, std::shared_ptr<Input> input) : model(std::move(model)), input(std::move(input)) {}
58
59 // Builder methods for fluent configuration.
60
62 ChatRequest& WithSystemPrompt(std::string prompt) {
63 system_prompt = std::move(prompt);
64 return *this;
65 }
66
69 previous_response_id = std::move(id);
70 return *this;
71 }
72
75 format.schema = util::NormalizeSchema(std::move(format.schema));
76 response_format = std::move(format);
77 return *this;
78 }
79
81 ChatRequest& AddTool(std::shared_ptr<Tool> tool) {
82 tools.push_back(std::move(tool));
83 return *this;
84 }
85
88 file_ids.push_back(std::move(file_id));
89 return *this;
90 }
91
94 image_ids.push_back(std::move(image_id));
95 return *this;
96 }
97
99 ChatRequest& AddImageUrl(std::string url) {
100 image_urls.push_back(std::move(url));
101 return *this;
102 }
103
105 ChatRequest& WithTemperature(float temperature) {
106 options.WithTemperature(temperature);
107 return *this;
108 }
109
111 ChatRequest& WithMaxTokens(int max_tokens) {
112 options.WithMaxTokens(max_tokens);
113 return *this;
114 }
115
117 ChatRequest& WithTopK(int top_k) {
118 options.WithTopK(top_k);
119 return *this;
120 }
121
123 ChatRequest& WithTopP(float top_p) {
124 options.WithTopP(top_p);
125 return *this;
126 }
127
129 ChatRequest& WithFrequencyPenalty(float frequency_penalty) {
130 options.WithFrequencyPenalty(frequency_penalty);
131 return *this;
132 }
133
135 ChatRequest& WithPresencePenalty(float presence_penalty) {
136 options.WithPresencePenalty(presence_penalty);
137 return *this;
138 }
139
142 options.WithSeed(seed);
143 return *this;
144 }
145};
146
149 std::string text;
150 std::vector<std::shared_ptr<InternalToolCall>> tools_called;
151 std::vector<ToolCallRequest> tool_call_requests;
152 std::string response_id;
153 int tokens_used = 0;
154};
155
156} // namespace core
157} // namespace foresthub
158
159#endif // FORESTHUB_CORE_TYPES_HPP
Polymorphic input types for chat requests.
Wrapper for nlohmann/json that works around abs macro conflicts.
Model metadata and capability identifiers.
Core abstractions: requests, responses, tools, input types, and provider interface.
std::string ModelID
Unique identifier for an LLM model.
Definition model.hpp:23
std::string FileID
Unique identifier for an uploaded file.
Definition types.hpp:29
json NormalizeSchema(json schema)
Wraps a minimal properties-only JSON object into a full JSON Schema.
Top-level namespace for the ForestHub SDK.
Minimal Optional<T> polyfill for C++14 compatibility.
Model-specific generation options (temperature, max_tokens, etc.).
JSON Schema normalization utilities.
Minimal Optional<T> polyfill for C++14 compatibility.
Definition optional.hpp:21
std::string previous_response_id
Previous response ID for multi-turn context.
Definition types.hpp:43
std::vector< std::shared_ptr< Tool > > tools
Tools available to the model.
Definition types.hpp:45
ChatRequest & WithPreviousResponseId(std::string id)
Link to a previous response for multi-turn context.
Definition types.hpp:68
ChatRequest & WithTopK(int top_k)
Set the top-k sampling limit.
Definition types.hpp:117
ChatRequest & AddImageUrl(std::string url)
Attach an image by URL.
Definition types.hpp:99
ChatRequest & WithTopP(float top_p)
Set the nucleus sampling cutoff.
Definition types.hpp:123
ChatRequest & WithPresencePenalty(float presence_penalty)
Set the presence penalty.
Definition types.hpp:135
std::vector< FileID > file_ids
Attached file identifiers.
Definition types.hpp:46
ModelID model
Target model identifier.
Definition types.hpp:40
ChatRequest & AddFileId(FileID file_id)
Attach an uploaded file to the request.
Definition types.hpp:87
std::vector< FileID > image_ids
Attached image identifiers.
Definition types.hpp:47
std::vector< std::string > image_urls
Attached image URLs.
Definition types.hpp:48
ChatRequest & WithTemperature(float temperature)
Set the sampling temperature.
Definition types.hpp:105
ChatRequest(ModelID model, std::shared_ptr< Input > input)
Construct a request with model and input.
Definition types.hpp:57
ChatRequest & AddTool(std::shared_ptr< Tool > tool)
Append a tool to the request.
Definition types.hpp:81
foresthub::Optional< ResponseFormat > response_format
Optional structured output format.
Definition types.hpp:44
ChatRequest & AddImageId(FileID image_id)
Attach an uploaded image to the request.
Definition types.hpp:93
ChatRequest & WithSystemPrompt(std::string prompt)
Set the system prompt.
Definition types.hpp:62
ChatRequest()=default
Default constructor. Use the two-argument constructor or builder methods for configuration.
Options options
Generation parameters.
Definition types.hpp:49
ChatRequest & WithMaxTokens(int max_tokens)
Set the maximum number of tokens to generate.
Definition types.hpp:111
std::shared_ptr< Input > input
Polymorphic input (InputString or InputItems).
Definition types.hpp:41
std::string system_prompt
System-level instructions.
Definition types.hpp:42
ChatRequest & WithSeed(int seed)
Set the random seed for deterministic output.
Definition types.hpp:141
ChatRequest & WithResponseFormat(ResponseFormat format)
Set the structured output format.
Definition types.hpp:74
ChatRequest & WithFrequencyPenalty(float frequency_penalty)
Set the frequency penalty.
Definition types.hpp:129
Chat completion response from an LLM provider.
Definition types.hpp:148
std::vector< ToolCallRequest > tool_call_requests
Pending function calls requested by the model.
Definition types.hpp:151
std::string text
Generated text output.
Definition types.hpp:149
std::vector< std::shared_ptr< InternalToolCall > > tools_called
Log of internal tools invoked by the model.
Definition types.hpp:150
std::string response_id
Provider-assigned response identifier.
Definition types.hpp:152
int tokens_used
Total tokens consumed.
Definition types.hpp:153
Model-specific generation options.
Definition options.hpp:17
Structured output format with JSON schema constraints.
Definition types.hpp:32
std::string name
Format name.
Definition types.hpp:33
std::string description
Human-readable description.
Definition types.hpp:35
json schema
JSON schema the response must conform to.
Definition types.hpp:34
Tool system: ExternalTool, FunctionTool, WebSearch, and tool call types.