Retrieve the model context size for use in UI and tools.

This commit is contained in:
Bartosz Taudul
2025-05-22 21:18:47 +02:00
parent b33110e53e
commit a1b67e4299
5 changed files with 7 additions and 12 deletions

View File

@@ -205,7 +205,8 @@ void TracyLlm::Draw()
return;
}
if( m_api->GetModels().empty() )
const auto& models = m_api->GetModels();
if( models.empty() )
{
ImGui::PushFont( g_fonts.big );
ImGui::Dummy( ImVec2( 0, ( ImGui::GetContentRegionAvail().y - ImGui::GetTextLineHeight() * 2 ) * 0.5f ) );
@@ -217,7 +218,7 @@ void TracyLlm::Draw()
return;
}
const auto ctxSize = m_api->GetContextSize();
const auto ctxSize = models[m_modelIdx].contextSize;
if( ctxSize > 0 )
{
ImGui::Spacing();
@@ -692,7 +693,7 @@ bool TracyLlm::OnResponse( const nlohmann::json& json )
auto tool = lines[0];
lines.erase( lines.begin() );
lock.unlock();
const auto reply = m_tools.HandleToolCalls( tool, lines, *m_api );
const auto reply = m_tools.HandleToolCalls( tool, lines, m_api->GetModels()[m_modelIdx].contextSize );
const auto output = "<tool_output>\n" + reply.reply;
m_usedCtx += output.size() / 4;
lock.lock();

View File

@@ -34,7 +34,6 @@ void TracyLlmApi::SetupCurl()
bool TracyLlmApi::Connect( const char* url )
{
m_contextSize = -1;
m_url = url;
m_models.clear();
if( m_curl ) curl_easy_cleanup( m_curl );

View File

@@ -34,7 +34,6 @@ public:
[[nodiscard]] bool IsConnected() const { return m_curl != nullptr; }
[[nodiscard]] const std::vector<LlmModel>& GetModels() const { return m_models; }
[[nodiscard]] int GetContextSize() const { return m_contextSize; }
private:
void SetupCurl();
@@ -47,7 +46,6 @@ private:
Type m_type;
std::vector<LlmModel> m_models;
int m_contextSize;
};
}

View File

@@ -6,7 +6,6 @@
#include <tidybuffio.h>
#include <time.h>
#include "TracyLlmApi.hpp"
#include "TracyLlmTools.hpp"
constexpr const char* NoNetworkAccess = "Internet access is disabled by the user. You may inform the user that he can enable it in the settings, so that you can use the tools to gather information.";
@@ -43,9 +42,9 @@ static std::string UrlEncode( const std::string& str )
return out;
}
TracyLlmTools::ToolReply TracyLlmTools::HandleToolCalls( const std::string& name, const std::vector<std::string>& args, const TracyLlmApi& api)
TracyLlmTools::ToolReply TracyLlmTools::HandleToolCalls( const std::string& name, const std::vector<std::string>& args, int contextSize )
{
m_ctxSize = api.GetContextSize();
m_ctxSize = contextSize;
if( name == "fetch_web_page" )
{

View File

@@ -9,8 +9,6 @@
namespace tracy
{
class TracyLlmApi;
class TracyLlmTools
{
public:
@@ -20,7 +18,7 @@ public:
std::string image;
};
ToolReply HandleToolCalls( const std::string& name, const std::vector<std::string>& args, const TracyLlmApi& api );
ToolReply HandleToolCalls( const std::string& name, const std::vector<std::string>& args, int contextSize );
std::string GetCurrentTime();
bool m_netAccess = true;