Support adding messages completely defined by json.

This commit is contained in:
Bartosz Taudul
2025-12-29 17:01:09 +01:00
parent c9443db053
commit dedc50e848
2 changed files with 12 additions and 0 deletions

View File

@@ -717,6 +717,17 @@ void TracyLlm::AddMessageBlocking( std::string&& str, const char* role, std::uni
if( lock ) lock.unlock();
}
void TracyLlm::AddMessageBlocking( nlohmann::json&& json, std::unique_lock<std::mutex>& lock )
{
auto dump = json.dump();
const auto tokens = m_api ? m_api->Tokenize( dump, m_modelIdx ) : -1;
m_usedCtx += tokens >= 0 ? tokens : dump.size() / 4;
if( lock ) lock.lock();
m_chat.emplace_back( std::move( json ) );
if( lock ) lock.unlock();
}
void TracyLlm::AddAttachment( std::string&& str, const char* role )
{
AddMessage( "<attachment>\n" + std::move( str ), role );

View File

@@ -62,6 +62,7 @@ private:
void QueueConnect();
void AddMessageBlocking( std::string&& str, const char* role, std::unique_lock<std::mutex>& lock );
void AddMessageBlocking( nlohmann::json&& json, std::unique_lock<std::mutex>& lock );
void ManageContext( std::unique_lock<std::mutex>& lock );
void SendMessage( std::unique_lock<std::mutex>& lock );