0
0
mirror of https://github.com/wolfpld/tracy.git synced 2026-01-18 17:11:26 +01:00

Implement separate-channel non-streamed chat completion requests.

This commit is contained in:
Bartosz Taudul
2026-01-11 18:54:11 +01:00
parent 761cb1041b
commit 9b5cbf835d
2 changed files with 25 additions and 0 deletions

View File

@@ -248,6 +248,30 @@ int TracyLlmApi::Tokenize( const std::string& text, int modelIdx )
return -1;
}
nlohmann::json TracyLlmApi::SendMessage( const nlohmann::json& chat, int modelIdx )
{
assert( m_curl );
nlohmann::json req = {
{ "model", m_models[modelIdx].name },
{ "messages", chat }
};
auto data = req.dump( -1, ' ', false, nlohmann::json::error_handler_t::replace );
std::string buf;
auto res = PostRequest( m_url + "/v1/chat/completions", data, buf, true );
if( res != 200 ) return {};
try
{
return nlohmann::json::parse( buf );
}
catch( const std::exception& )
{
return {};
}
}
int64_t TracyLlmApi::GetRequest( const std::string& url, std::string& response )
{
assert( m_curl );

View File

@@ -35,6 +35,7 @@ public:
bool ChatCompletion( const nlohmann::json& req, const std::function<bool(const nlohmann::json&)>& callback, int modelIdx );
bool Embeddings( const nlohmann::json& req, nlohmann::json& response, bool separateConnection = false );
[[nodiscard]] int Tokenize( const std::string& text, int modelIdx );
[[nodiscard]] nlohmann::json SendMessage( const nlohmann::json& chat, int modelIdx );
[[nodiscard]] bool IsConnected() const { return m_curl != nullptr; }
[[nodiscard]] const std::vector<LlmModel>& GetModels() const { return m_models; }