mirror of
https://github.com/wolfpld/tracy
synced 2026-01-19 04:52:09 +00:00
Add fast model selection to the UI.
This commit is contained in:
@@ -42,6 +42,7 @@ void LoadConfig()
|
||||
if( ini_sget( ini, "llm", "enabled", "%d", &v ) ) s_config.llm = v;
|
||||
if( v2 = ini_get( ini, "llm", "address" ); v2 ) s_config.llmAddress = v2;
|
||||
if( v2 = ini_get( ini, "llm", "model" ); v2 ) s_config.llmModel = v2;
|
||||
if( v2 = ini_get( ini, "llm", "fastModel" ); v2 ) s_config.llmFastModel = v2;
|
||||
if( v2 = ini_get( ini, "llm", "embeddings" ); v2 ) s_config.llmEmbeddingsModel = v2;
|
||||
if( v2 = ini_get( ini, "llm", "useragent" ); v2 ) s_config.llmUserAgent = v2;
|
||||
if( v2 = ini_get( ini, "llm", "searchIdentifier" ); v2 ) s_config.llmSearchIdentifier = v2;
|
||||
@@ -89,6 +90,7 @@ bool SaveConfig()
|
||||
fprintf( f, "enabled = %i\n", (int)s_config.llm );
|
||||
fprintf( f, "address = %s\n", s_config.llmAddress.c_str() );
|
||||
fprintf( f, "model = %s\n", s_config.llmModel.c_str() );
|
||||
fprintf( f, "fastModel = %s\n", s_config.llmFastModel.c_str() );
|
||||
fprintf( f, "embeddings = %s\n", s_config.llmEmbeddingsModel.c_str() );
|
||||
fprintf( f, "useragent = %s\n", s_config.llmUserAgent.c_str() );
|
||||
fprintf( f, "searchIdentifier = %s\n", s_config.llmSearchIdentifier.c_str() );
|
||||
|
||||
@@ -38,6 +38,7 @@ struct Config
|
||||
#endif
|
||||
std::string llmAddress = "http://localhost:11434";
|
||||
std::string llmModel;
|
||||
std::string llmFastModel;
|
||||
std::string llmEmbeddingsModel;
|
||||
std::string llmUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36";
|
||||
std::string llmSearchIdentifier;
|
||||
|
||||
@@ -197,7 +197,7 @@ void TracyLlm::Draw()
|
||||
|
||||
const auto& models = m_api->GetModels();
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( "Model:" );
|
||||
TextDisabledUnformatted( "Chat model:" );
|
||||
ImGui::SameLine();
|
||||
if( models.empty() || m_modelIdx < 0 )
|
||||
{
|
||||
@@ -230,7 +230,40 @@ void TracyLlm::Draw()
|
||||
}
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( "Embeddings:" );
|
||||
TextDisabledUnformatted( "Fast model:" );
|
||||
ImGui::SameLine();
|
||||
if( models.empty() || m_fastIdx < 0 )
|
||||
{
|
||||
ImGui::TextUnformatted( "No models available" );
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::SetNextItemWidth( ImGui::GetContentRegionAvail().x );
|
||||
if( ImGui::BeginCombo( "##fastmodel", models[m_fastIdx].name.c_str() ) )
|
||||
{
|
||||
for( size_t i = 0; i < models.size(); ++i )
|
||||
{
|
||||
const auto& model = models[i];
|
||||
if( model.embeddings ) continue;
|
||||
if( ImGui::Selectable( model.name.c_str(), i == m_fastIdx ) )
|
||||
{
|
||||
m_fastIdx = i;
|
||||
s_config.llmFastModel = model.name;
|
||||
SaveConfig();
|
||||
}
|
||||
if( m_fastIdx == i ) ImGui::SetItemDefaultFocus();
|
||||
if( !model.quant.empty() )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled( "(%s)", model.quant.c_str() );
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::AlignTextToFramePadding();
|
||||
TextDisabledUnformatted( "Embeddings model:" );
|
||||
ImGui::SameLine();
|
||||
if( models.empty() || m_embedIdx < 0 )
|
||||
{
|
||||
@@ -644,6 +677,7 @@ void TracyLlm::WorkerThread()
|
||||
void TracyLlm::UpdateModels()
|
||||
{
|
||||
m_modelIdx = -1;
|
||||
m_fastIdx = -1;
|
||||
m_embedIdx = -1;
|
||||
|
||||
auto& models = m_api->GetModels();
|
||||
@@ -664,6 +698,23 @@ void TracyLlm::UpdateModels()
|
||||
m_modelIdx = std::distance( models.begin(), it );
|
||||
}
|
||||
|
||||
it = std::ranges::find_if( models, []( const auto& model ) { return model.name == s_config.llmFastModel; } );
|
||||
if( it == models.end() )
|
||||
{
|
||||
for( int i=0; i<models.size(); i++ )
|
||||
{
|
||||
if( !models[i].embeddings )
|
||||
{
|
||||
m_fastIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fastIdx = std::distance( models.begin(), it );
|
||||
}
|
||||
|
||||
it = std::ranges::find_if( models, []( const auto& model ) { return model.name == s_config.llmEmbeddingsModel; } );
|
||||
if( it == models.end() )
|
||||
{
|
||||
|
||||
@@ -76,6 +76,7 @@ private:
|
||||
std::unique_ptr<TracyLlmTools> m_tools;
|
||||
|
||||
int m_modelIdx;
|
||||
int m_fastIdx;
|
||||
int m_embedIdx;
|
||||
|
||||
std::atomic<bool> m_exit;
|
||||
|
||||
Reference in New Issue
Block a user