mirror of
https://github.com/wolfpld/tracy.git
synced 2026-06-08 00:23:47 +00:00
Display label with assistant model name and reply duration for each message.
This commit is contained in:
@@ -549,6 +549,10 @@ void TracyLlm::Draw()
|
||||
}
|
||||
}
|
||||
|
||||
std::string model;
|
||||
uint64_t timeStart = 0;
|
||||
uint64_t timeEnd = 0;
|
||||
|
||||
int turnIdx = 0;
|
||||
for( auto it = m_chat.begin(); it != m_chat.end(); ++it )
|
||||
{
|
||||
@@ -567,6 +571,20 @@ void TracyLlm::Draw()
|
||||
{
|
||||
if( line.contains( "content" ) && line["content"].get_ref<const std::string&>().starts_with( "<attachment>\n" ) ) role = TracyLlmChat::TurnRole::Attachment;
|
||||
}
|
||||
else if( role == TracyLlmChat::TurnRole::Assistant && timeStart == 0 && line.contains( "model" ) && line.contains( "time_start" ) )
|
||||
{
|
||||
model = line["model"].get_ref<const std::string&>();
|
||||
timeStart = line["time_start"].get<uint64_t>();
|
||||
}
|
||||
if( line.contains( "time_end" ) )
|
||||
{
|
||||
timeEnd = line["time_end"].get<uint64_t>();
|
||||
if( timeStart != 0 )
|
||||
{
|
||||
m_chatUi->SetModelTimeLabel( model.c_str(), timeEnd - timeStart );
|
||||
timeStart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PushID( turnIdx++ );
|
||||
TracyLlmChat::Think think = TracyLlmChat::Think::Hide;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyLlmChat.hpp"
|
||||
#include "TracyMouse.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "../Fonts.hpp"
|
||||
#include "../../public/common/TracyForceInline.hpp"
|
||||
|
||||
@@ -141,6 +142,13 @@ TracyLlmChat::~TracyLlmChat()
|
||||
delete[] m_width;
|
||||
}
|
||||
|
||||
void TracyLlmChat::SetModelTimeLabel( const char* model, uint64_t duration_ns )
|
||||
{
|
||||
char buf[128];
|
||||
snprintf( buf, sizeof( buf ), "%s » %s", model, TimeToString( duration_ns ) );
|
||||
m_label = buf;
|
||||
}
|
||||
|
||||
void TracyLlmChat::Begin()
|
||||
{
|
||||
float max = 0;
|
||||
@@ -156,12 +164,21 @@ void TracyLlmChat::Begin()
|
||||
m_thinkOpen = false;
|
||||
m_thinkIdx = 0;
|
||||
m_roleIdx = 0;
|
||||
m_label.clear();
|
||||
}
|
||||
|
||||
void TracyLlmChat::End()
|
||||
{
|
||||
if( m_role != TurnRole::None )
|
||||
{
|
||||
if( m_role == TurnRole::Assistant && !m_label.empty() )
|
||||
{
|
||||
ImGui::Spacing();
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::TextDisabled( "%s", m_label.c_str() );
|
||||
ImGui::PopFont();
|
||||
m_label.clear();
|
||||
}
|
||||
NormalScope();
|
||||
ImGui::EndGroup();
|
||||
ImGui::PopID();
|
||||
@@ -180,6 +197,14 @@ bool TracyLlmChat::Turn( TurnRole role, std::vector<nlohmann::json>::iterator it
|
||||
{
|
||||
if( m_role != TurnRole::None )
|
||||
{
|
||||
if( m_role == TurnRole::Assistant && !m_label.empty() )
|
||||
{
|
||||
ImGui::Spacing();
|
||||
ImGui::PushFont( g_fonts.normal, FontSmall );
|
||||
ImGui::TextDisabled( "%s", m_label.c_str() );
|
||||
ImGui::PopFont();
|
||||
m_label.clear();
|
||||
}
|
||||
NormalScope();
|
||||
ImGui::EndGroup();
|
||||
ImGui::PopID();
|
||||
@@ -311,13 +336,13 @@ bool TracyLlmChat::Turn( TurnRole role, std::vector<nlohmann::json>::iterator it
|
||||
{
|
||||
NormalScope();
|
||||
m_markdown.Print( content.c_str(), content.size() );
|
||||
if( !last && think == Think::Hide && roleStr == "assistant" ) ImGui::Spacing();
|
||||
if( roleStr == "assistant" ) ImGui::Spacing();
|
||||
}
|
||||
}
|
||||
}
|
||||
if( think != Think::Hide && json.contains( "tool_calls" ) )
|
||||
{
|
||||
ThinkScope( !roleChange || json.contains( "content" ) );
|
||||
ThinkScope( !roleChange && !json.contains( "content" ) );
|
||||
if( m_thinkOpen )
|
||||
{
|
||||
ImGui::PushStyleColor( ImGuiCol_Text, ImVec4( 0.5f, 0.5f, 0.5f, 1.f ) );
|
||||
|
||||
@@ -42,6 +42,7 @@ public:
|
||||
void End();
|
||||
|
||||
bool Turn( TurnRole role, std::vector<nlohmann::json>::iterator it, const std::vector<nlohmann::json>::iterator& end, Think think, bool last );
|
||||
void SetModelTimeLabel( const char* model, uint64_t duration_ns );
|
||||
|
||||
private:
|
||||
void NormalScope();
|
||||
@@ -59,6 +60,7 @@ private:
|
||||
int m_roleIdx;
|
||||
|
||||
Markdown m_markdown;
|
||||
std::string m_label;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user