Don't crash on assert when a tool call is missing a parameter.

This commit is contained in:
Bartosz Taudul
2025-07-08 01:29:00 +02:00
parent 818d238f50
commit 55cf0139fd

View File

@@ -205,8 +205,20 @@ TracyLlmTools::~TracyLlmTools()
CancelManualEmbeddings();
}
#define Param(name) json[name].get_ref<const std::string&>()
#define ParamU32(name) json[name].get<uint32_t>()
static const std::string& GetParam( const nlohmann::json& json, const char* name )
{
if( !json.contains( name ) ) throw std::runtime_error( "Error: missing parameter: " + std::string( name ) );
return json[name].get_ref<const std::string&>();
}
static uint32_t GetParamU32( const nlohmann::json& json, const char* name )
{
if( !json.contains( name ) ) throw std::runtime_error( "Error: missing parameter: " + std::string( name ) );
return json[name].get<uint32_t>();
}
#define Param(name) GetParam( json, name )
#define ParamU32(name) GetParamU32( json, name )
TracyLlmTools::ToolReply TracyLlmTools::HandleToolCalls( const nlohmann::json& json, TracyLlmApi& api, int contextSize, bool hasEmbeddingsModel )
{
@@ -245,7 +257,7 @@ TracyLlmTools::ToolReply TracyLlmTools::HandleToolCalls( const nlohmann::json& j
}
return { .reply = "Unknown tool call: " + name };
}
catch( const nlohmann::json::exception& e )
catch( const std::exception& e )
{
return { .reply = e.what() };
}