Fix possible crash.

This commit is contained in:
Bartosz Taudul
2025-08-23 21:22:32 +02:00
parent 69836f3166
commit 67ba5b7727

View File

@@ -850,13 +850,17 @@ bool TracyLlm::OnResponse( const nlohmann::json& json )
const auto& str = content.get_ref<const std::string&>();
std::string responseStr;
bool done;
bool done = false;
try
{
auto& node = json["choices"][0];
auto& delta = node["delta"];
if( delta.contains( "content" ) && delta["content"].is_string() ) responseStr = delta["content"].get_ref<const std::string&>();
done = !node["finish_reason"].empty();
auto& choices = json["choices"];
if( !choices.empty() )
{
auto& node = choices[0];
auto& delta = node["delta"];
if( delta.contains( "content" ) && delta["content"].is_string() ) responseStr = delta["content"].get_ref<const std::string&>();
done = !node["finish_reason"].empty();
}
}
catch( const nlohmann::json::exception& e )
{