TT Client Library 1.0.0
C++ library for Tandem Tales clients.
Loading...
Searching...
No Matches
tt::ExternalAPI Class Reference

Represents the external API used for text embedding and completion. More...

#include <tt/ExternalAPI.h>

Public Member Functions

 ExternalAPI (const std::string &key)
 Constructs an ExternalAPI object.
 ExternalAPI ()
 Constructs an ExternalAPI object.
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.
std::string complete (const std::vector< std::string > &messages)
 Queries the external text completion API and returns its response as a string.
std::string complete (const std::string &message)
 Queries the external text completion API and returns its response as a string.
void setReasoning (const std::optional< std::string > &value=std::nullopt)
 Sets the reasoning level used by the large language model during text completion.
void setMaxT (const std::optional< int > &value=std::nullopt)
 Sets the maximum number of tokens the model may use to generate its response.
void setTemp (const std::optional< float > &value=std::nullopt)
 Sets the temperature, which influences the randomness of the response.
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.
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 probabilities add to p.
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 probability is p times the probability of the most likely token.
void setKey (const std::string &k)
 Sets the API key.
const std::optional< std::string > & getReasoning () const
 Gives the current reasoning value.
const std::optional< int > & getMaxT () const
 Gives the current maxt value.
const std::optional< float > & getTemp () const
 Gives the current temperature value.
const std::optional< int > & getTopK () const
 Gives the current topk value.
const std::optional< float > & getTopP () const
 Gives the current topp value.
const std::optional< float > & getMinP () const
 Gives the current minp value.
const std::string & getKey () const
 Gives the API key.
const int getRemainingInTokens () const
 Gives the remaining amount of in tokens for completion.
const int getRemainingOutTokens () const
 Gives the remaining amount of out tokens for completion.
const int getRemainingEmbedTokens () const
 Gives the remaining amount of tokens for embed.
const int getInTokensUsed () const
 Gives the amount of in tokens used for completion.
const int getOutTokensUsed () const
 Gives the amount of out tokens used for completion.
const int getEmbedTokensUsed () const
 Gives the amount of tokens used for embed.

Static Public Attributes

static constexpr std::string_view INVALID_KEY = "API-INVALID-KEY"
 Used for checking whether a key has been set.
static constexpr std::string_view EMBED_URL = "https://openrouter.ai/api/v1/embeddings"
 The URL to which large language model text embedding requests will be sent.
static constexpr std::string_view EMBED_MODEL = "qwen/qwen3-embedding-8b"
 The model to be used for large language model text embedding requests.
static constexpr int EMBED_TOKENS_LIMIT = 1000000
 The maximum number of input tokens that can be used for text embedding requests.
static constexpr std::string_view COMPLETE_URL = "https://openrouter.ai/api/v1/chat/completions"
 The URL to which large language model text completion requests will be sent.
static constexpr std::string_view COMPLETE_MODEL = "deepseek/deepseek-v4-flash-0731"
 The large language model to be used for text completion requests.
static constexpr int COMPLETE_IN_TOKENS_LIMIT = 1000000
 The maximum number of input tokens that can be used for text completion requests.
static constexpr int COMPLETE_OUT_TOKENS_LIMIT = 1000000
 The maximum number of output tokens that can be used for text completion requests.
static constexpr int COMPLETE_SEED = 0
 The seed used for large language model text completion requests.

Detailed Description

Represents the external API used for text embedding and completion.

Constructor & Destructor Documentation

◆ ExternalAPI()

tt::ExternalAPI::ExternalAPI ( const std::string & key)

Constructs an ExternalAPI object.

Parameters
keythe api key to use

Member Function Documentation

◆ complete() [1/2]

std::string tt::ExternalAPI::complete ( const std::string & message)

Queries the external text completion API and returns its response as a string.

With a single string as input, the model will use its default system prompt and treat the string as a message from the user.

Each time this method is called, the number of tokens used in the prompt is added to complete_in_tokens and the number of tokens used in reasoning and completion is added to complete_out_tokens. If the number of tokens used exceeds COMPLETE_IN_TOKENS_LIMIT or COMPLETE_OUT_TOKENS_LIMIT respectively, this method will raise an exception.

Parameters
messagethe message from the user.
Returns
The response for the text completion API as a string
Exceptions
std::logic_errorif the client does not have an API key

◆ complete() [2/2]

std::string tt::ExternalAPI::complete ( const std::vector< std::string > & messages)

Queries the external text completion API and returns its response as a string.

Each time this method is called, the number of tokens used in the prompt is added to completeInTokens and the number of tokens used in reasoning and completion is added to completeOutTokens. If the number of tokens used exceeds COMPLETE_IN_TOKENS_LIMIT or COMPLETE_OUT_TOKENS_LIMIT respectively, this method will raise an exception.

Parameters
messagesAn array of strings representing a conversation. The first string will be used as the system prompt. Every odd numbered message will be treated as a message from the user. Every even numbered message (after the first) will be treated as a response from the assistant.
Returns
The response for the text completion API as a string
Exceptions
std::logic_errorif the client does not have an API key

◆ embed()

std::vector< float > tt::ExternalAPI::embed ( std::string text,
int dim = 1024 )

Queries the external text embedding API and returns its response as a vector of floats.

Each time this method is called, the number of tokens used is added to embedTokens. If the number of tokens used exceeds EMBED_TOKENS_LIMIT, this method will raise an exception.

Parameters
textThe text which will be embedded as an array of floats.
dimThe number of dimensions in the returned array.
Returns
the vector embedding of the text as a vector of floats

◆ getEmbedTokensUsed()

const int tt::ExternalAPI::getEmbedTokensUsed ( ) const

Gives the amount of tokens used for embed.

Returns
the amount of used tokens

◆ getInTokensUsed()

const int tt::ExternalAPI::getInTokensUsed ( ) const

Gives the amount of in tokens used for completion.

Returns
the amount of used in tokens

◆ getKey()

const std::string & tt::ExternalAPI::getKey ( ) const

Gives the API key.

Returns
the key

◆ getMaxT()

const std::optional< int > & tt::ExternalAPI::getMaxT ( ) const

Gives the current maxt value.

Returns
the current maxt value

◆ getMinP()

const std::optional< float > & tt::ExternalAPI::getMinP ( ) const

Gives the current minp value.

Returns
the current minp value

◆ getOutTokensUsed()

const int tt::ExternalAPI::getOutTokensUsed ( ) const

Gives the amount of out tokens used for completion.

Returns
the amount of used out tokens

◆ getReasoning()

const std::optional< std::string > & tt::ExternalAPI::getReasoning ( ) const

Gives the current reasoning value.

Returns
the current reasoning value

◆ getRemainingEmbedTokens()

const int tt::ExternalAPI::getRemainingEmbedTokens ( ) const

Gives the remaining amount of tokens for embed.

Returns
the remaining amount of tokens

◆ getRemainingInTokens()

const int tt::ExternalAPI::getRemainingInTokens ( ) const

Gives the remaining amount of in tokens for completion.

Returns
the remaining amount of tokens

◆ getRemainingOutTokens()

const int tt::ExternalAPI::getRemainingOutTokens ( ) const

Gives the remaining amount of out tokens for completion.

Returns
the remaining amount of tokens

◆ getTemp()

const std::optional< float > & tt::ExternalAPI::getTemp ( ) const

Gives the current temperature value.

Returns
the current temperature value

◆ getTopK()

const std::optional< int > & tt::ExternalAPI::getTopK ( ) const

Gives the current topk value.

Returns
the current topk value

◆ getTopP()

const std::optional< float > & tt::ExternalAPI::getTopP ( ) const

Gives the current topp value.

Returns
the current topp value

◆ setKey()

void tt::ExternalAPI::setKey ( const std::string & k)

Sets the API key.

Parameters
kthe key

◆ setMaxT()

void tt::ExternalAPI::setMaxT ( const std::optional< int > & value = std::nullopt)

Sets the maximum number of tokens the model may use to generate its response.

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe maxt to use

◆ setMinP()

void tt::ExternalAPI::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 probability is p times the probability of the most likely token.

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe minp to use

◆ setReasoning()

void tt::ExternalAPI::setReasoning ( const std::optional< std::string > & value = std::nullopt)

Sets the reasoning level used by the large language model during text completion.

Value includes max, high, medium, low, and none

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe reasoning level to use

◆ setTemp()

void tt::ExternalAPI::setTemp ( const std::optional< float > & value = std::nullopt)

Sets the temperature, which influences the randomness of the response.

A value of 0.0 will give deterministic responses. The max value is 2.0.

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe temperature to use

◆ setTopK()

void tt::ExternalAPI::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.

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe topk to use

◆ setTopP()

void tt::ExternalAPI::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 probabilities add to p.

To use the default value, you can pass std::nullopt as a parameter, or pass no parameter at all.

Parameters
valuethe topp to use

The documentation for this class was generated from the following files: