6#include <nlohmann/json.hpp>
19 static constexpr std::string_view
INVALID_KEY =
"API-INVALID-KEY";
22 static constexpr std::string_view
EMBED_URL =
"https://openrouter.ai/api/v1/embeddings";
24 static constexpr std::string_view
EMBED_MODEL =
"qwen/qwen3-embedding-8b";
29 static constexpr std::string_view
COMPLETE_URL =
"https://openrouter.ai/api/v1/chat/completions";
31 static constexpr std::string_view
COMPLETE_MODEL =
"deepseek/deepseek-v4-flash-0731";
58 std::vector<float>
embed(std::string text,
int dim = 1024);
79 std::string
complete(
const std::vector<std::string>& messages);
97 std::string
complete(
const std::string& message);
107 void setReasoning(
const std::optional<std::string>& value = std::nullopt);
116 void setMaxT(
const std::optional<int>& value = std::nullopt);
126 void setTemp(
const std::optional<float>& value = std::nullopt);
136 void setTopK(
const std::optional<int>& value = std::nullopt);
146 void setTopP(
const std::optional<float>& value = std::nullopt);
157 void setMinP(
const std::optional<float>& value = std::nullopt);
163 void setKey(
const std::string& k);
177 const std::optional<int>&
getMaxT()
const;
184 const std::optional<float>&
getTemp()
const;
191 const std::optional<int>&
getTopK()
const;
198 const std::optional<float>&
getTopP()
const;
205 const std::optional<float>&
getMinP()
const;
211 const std::string&
getKey()
const;
253 void checkKey()
const;
261 void checkInLimit(
int used,
int limit)
const;
269 void checkOutLimit(
int used,
int limit)
const;
278 void checkNominal(
const std::string& name,
const std::string& value,
const std::vector<std::string>& values)
const;
288 void checkInt(
const std::string& name,
int value,
int min,
int max);
298 void checkFloat(
const std::string& name,
float value,
float min,
float max);
306 int completeInTokens = 0;
308 int completeOutTokens = 0;
313 std::optional<std::string> reasoning = std::nullopt;
315 std::optional<int> maxt = std::nullopt;
317 std::optional<float> temp = std::nullopt;
319 std::optional<int> topk = std::nullopt;
322 std::optional<float> topp = std::nullopt;
326 std::optional<float> minp = std::nullopt;
const std::optional< float > & getTemp() const
Gives the current temperature value.
Definition ExternalAPI.cpp:191
const int getRemainingOutTokens() const
Gives the remaining amount of out tokens for completion.
Definition ExternalAPI.cpp:221
const std::optional< float > & getTopP() const
Gives the current topp value.
Definition ExternalAPI.cpp:201
ExternalAPI(const std::string &key)
Constructs an ExternalAPI object.
Definition ExternalAPI.cpp:10
static constexpr int COMPLETE_SEED
The seed used for large language model text completion requests.
Definition ExternalAPI.h:37
void setMaxT(const std::optional< int > &value=std::nullopt)
Sets the maximum number of tokens the model may use to generate its response.
Definition ExternalAPI.cpp:145
void setTopP(const std::optional< float > &value=std::nullopt)
When choosing a next token to add to the output, the model may only choose from tokens whose probabil...
Definition ExternalAPI.cpp:162
std::vector< float > embed(std::string text, int dim=1024)
Queries the external text embedding API and returns its response as a vector of floats.
Definition ExternalAPI.cpp:21
const std::optional< int > & getMaxT() const
Gives the current maxt value.
Definition ExternalAPI.cpp:186
static constexpr std::string_view COMPLETE_URL
The URL to which large language model text completion requests will be sent.
Definition ExternalAPI.h:29
void setTemp(const std::optional< float > &value=std::nullopt)
Sets the temperature, which influences the randomness of the response.
Definition ExternalAPI.cpp:150
const std::string & getKey() const
Gives the API key.
Definition ExternalAPI.cpp:211
static constexpr int COMPLETE_IN_TOKENS_LIMIT
The maximum number of input tokens that can be used for text completion requests.
Definition ExternalAPI.h:33
void setMinP(const std::optional< float > &value=std::nullopt)
When choosing a next token to add to the output, the model may only choose from tokens whose probabil...
Definition ExternalAPI.cpp:169
const int getRemainingEmbedTokens() const
Gives the remaining amount of tokens for embed.
Definition ExternalAPI.cpp:226
void setKey(const std::string &k)
Sets the API key.
Definition ExternalAPI.cpp:176
static constexpr std::string_view INVALID_KEY
Used for checking whether a key has been set.
Definition ExternalAPI.h:19
static constexpr std::string_view COMPLETE_MODEL
The large language model to be used for text completion requests.
Definition ExternalAPI.h:31
static constexpr std::string_view EMBED_MODEL
The model to be used for large language model text embedding requests.
Definition ExternalAPI.h:24
const int getEmbedTokensUsed() const
Gives the amount of tokens used for embed.
Definition ExternalAPI.cpp:241
void setTopK(const std::optional< int > &value=std::nullopt)
When choosing a next token to add to the output, the model may only choose from the best k tokens.
Definition ExternalAPI.cpp:157
const int getInTokensUsed() const
Gives the amount of in tokens used for completion.
Definition ExternalAPI.cpp:231
const std::optional< int > & getTopK() const
Gives the current topk value.
Definition ExternalAPI.cpp:196
void setReasoning(const std::optional< std::string > &value=std::nullopt)
Sets the reasoning level used by the large language model during text completion.
Definition ExternalAPI.cpp:138
std::string complete(const std::vector< std::string > &messages)
Queries the external text completion API and returns its response as a string.
Definition ExternalAPI.cpp:60
static constexpr std::string_view EMBED_URL
The URL to which large language model text embedding requests will be sent.
Definition ExternalAPI.h:22
const int getOutTokensUsed() const
Gives the amount of out tokens used for completion.
Definition ExternalAPI.cpp:236
const std::optional< float > & getMinP() const
Gives the current minp value.
Definition ExternalAPI.cpp:206
ExternalAPI()
Constructs an ExternalAPI object.
Definition ExternalAPI.cpp:16
static constexpr int COMPLETE_OUT_TOKENS_LIMIT
The maximum number of output tokens that can be used for text completion requests.
Definition ExternalAPI.h:35
static constexpr int EMBED_TOKENS_LIMIT
The maximum number of input tokens that can be used for text embedding requests.
Definition ExternalAPI.h:26
const std::optional< std::string > & getReasoning() const
Gives the current reasoning value.
Definition ExternalAPI.cpp:181
const int getRemainingInTokens() const
Gives the remaining amount of in tokens for completion.
Definition ExternalAPI.cpp:216
Tandem Tales is a platform that enables short, paired storytelling exercises between two agents over ...
Definition Client.h:22