2
0
mirror of https://github.com/wolfpld/tracy synced 2026-01-19 04:52:09 +00:00

Implement fast message queries.

This commit is contained in:
Bartosz Taudul
2026-01-11 18:56:19 +01:00
parent 9b5cbf835d
commit 2bf0a3c7f9
2 changed files with 23 additions and 0 deletions

View File

@@ -659,6 +659,14 @@ void TracyLlm::WorkerThread()
case Task::SendMessage:
SendMessage( lock );
break;
case Task::FastMessage:
{
lock.unlock();
auto response = m_api->SendMessage( m_currentJob->param2, m_fastIdx );
m_currentJob->callback2( response );
lock.lock();
break;
}
case Task::Tokenize:
{
lock.unlock();
@@ -799,6 +807,18 @@ bool TracyLlm::QueueSendMessage()
return true;
}
bool TracyLlm::QueueFastMessage( const nlohmann::json& req, std::function<void(nlohmann::json)> callback )
{
if( !m_api->IsConnected() || m_fastIdx < 0 ) return false;
m_jobs.emplace_back( std::make_shared<WorkItem>( WorkItem {
.task = Task::FastMessage,
.callback2 = std::move( callback ),
.param2 = req
} ) );
m_cv.notify_all();
return true;
}
void TracyLlm::AddMessage( std::string&& str, const char* role )
{
if( !m_api )

View File

@@ -28,6 +28,7 @@ class TracyLlm
{
Connect,
SendMessage,
FastMessage,
Tokenize
};
@@ -37,6 +38,7 @@ class TracyLlm
std::function<void()> callback;
std::function<void(nlohmann::json)> callback2;
std::string param;
nlohmann::json param2;
bool stop;
};
@@ -50,6 +52,7 @@ public:
void AddAttachment( std::string&& str, const char* role );
void AddMessage( std::string&& str, const char* role );
bool QueueSendMessage();
bool QueueFastMessage( const nlohmann::json& req, std::function<void(nlohmann::json)> callback );
bool m_show = false;