From 4250fa51c27bdf82fcf93f25c0ebd73c795dbb0e Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 11 May 2025 21:14:36 +0200 Subject: [PATCH] Add model selection to LLM UI. --- profiler/src/profiler/TracyLlm.cpp | 57 ++++++++++++++++++++++++------ profiler/src/profiler/TracyLlm.hpp | 1 + 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index a8473be9..a2a61655 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -4,6 +4,7 @@ #include "TracyConfig.hpp" #include "TracyImGui.hpp" #include "TracyLlm.hpp" +#include "TracyPrint.hpp" extern tracy::Config s_config; @@ -34,17 +35,7 @@ TracyLlm::TracyLlm() m_jobs.emplace_back( WorkItem { .task = Task::LoadModels, - .callback = [this] { - auto it = std::ranges::find_if( m_models, []( const auto& model ) { return model.name == s_config.llmModel; } ); - if( it == m_models.end() ) - { - m_modelIdx = 0; - } - else - { - m_modelIdx = std::distance( m_models.begin(), it ); - } - } + .callback = [this] { UpdateModels(); } } ); m_thread = std::thread( [this] { Worker(); } ); } @@ -102,6 +93,37 @@ void TracyLlm::Draw() return; } + if( ImGui::SmallButton( ICON_FA_ARROWS_ROTATE ) ) + { + std::lock_guard lock( m_lock ); + m_jobs.emplace_back( WorkItem { + .task = Task::LoadModels, + .callback = [this] { UpdateModels(); } + } ); + m_cv.notify_all(); + } + ImGui::SameLine(); + ImGui::TextDisabled( "Model:" ); + ImGui::SameLine(); + ImGui::PushStyleVar( ImGuiStyleVar_FramePadding, ImVec2( 0, 0 ) ); + if( ImGui::BeginCombo( "##model", m_models[m_modelIdx].name.c_str() ) ) + { + for( size_t i = 0; i < m_models.size(); ++i ) + { + const auto& model = m_models[i]; + if( ImGui::Selectable( model.name.c_str(), i == m_modelIdx ) ) + { + m_modelIdx = i; + s_config.llmModel = model.name; + } + if( m_modelIdx == i ) ImGui::SetItemDefaultFocus(); + ImGui::SameLine(); + ImGui::TextDisabled( "(ctx: %s)", tracy::RealToString( m_models[i].ctxSize ) ); + } + ImGui::EndCombo(); + } + ImGui::PopStyleVar(); + ImGui::End(); } @@ -154,4 +176,17 @@ void TracyLlm::LoadModels() m_modelsLock.unlock(); } +void TracyLlm::UpdateModels() +{ + auto it = std::ranges::find_if( m_models, []( const auto& model ) { return model.name == s_config.llmModel; } ); + if( it == m_models.end() ) + { + m_modelIdx = 0; + } + else + { + m_modelIdx = std::distance( m_models.begin(), it ); + } +} + } diff --git a/profiler/src/profiler/TracyLlm.hpp b/profiler/src/profiler/TracyLlm.hpp index 7b69d57b..13128134 100644 --- a/profiler/src/profiler/TracyLlm.hpp +++ b/profiler/src/profiler/TracyLlm.hpp @@ -56,6 +56,7 @@ private: void Worker(); void LoadModels(); + void UpdateModels(); std::unique_ptr m_ollama;