diff --git a/profiler/src/profiler/TracyLlm.cpp b/profiler/src/profiler/TracyLlm.cpp index 49c9795e..2cf8ad91 100644 --- a/profiler/src/profiler/TracyLlm.cpp +++ b/profiler/src/profiler/TracyLlm.cpp @@ -242,6 +242,7 @@ void TracyLlm::Draw() m_embedIdx = i; s_config.llmEmbeddingsModel = model.name; SaveConfig(); + m_tools->SelectManualEmbeddings( model.name ); } if( m_embedIdx == i ) ImGui::SetItemDefaultFocus(); ImGui::SameLine(); @@ -326,18 +327,6 @@ void TracyLlm::Draw() m_tools->BuildManualEmbeddings( models[m_embedIdx].name, *m_api ); } if( m_embedIdx < 0 ) ImGui::EndDisabled(); - ImGui::SameLine(); - ImGui::PushFont( g_fonts.small ); - ImGui::AlignTextToFramePadding(); - if( !manualEmbeddingsState.done ) - { - tracy::TextDisabledUnformatted( "Embeddings not calculated" ); - } - else - { - ImGui::TextDisabled( "Embeddings calculated for model %s", manualEmbeddingsState.model.c_str() ); - } - ImGui::PopFont(); } const auto ctxSize = models[m_modelIdx].contextSize; @@ -576,6 +565,11 @@ void TracyLlm::UpdateModels() { m_embedIdx = std::distance( models.begin(), it ); } + + if( m_embedIdx >= 0 ) + { + m_tools->SelectManualEmbeddings( models[m_embedIdx].name ); + } } void TracyLlm::ResetChat() diff --git a/profiler/src/profiler/TracyLlmTools.cpp b/profiler/src/profiler/TracyLlmTools.cpp index b58709f1..dc1eed31 100644 --- a/profiler/src/profiler/TracyLlmTools.cpp +++ b/profiler/src/profiler/TracyLlmTools.cpp @@ -229,6 +229,23 @@ TracyLlmTools::EmbeddingState TracyLlmTools::GetManualEmbeddingsState() const return m_manualEmbeddingState; } +void TracyLlmTools::SelectManualEmbeddings( const std::string& model ) +{ + std::lock_guard lock( m_lock ); + assert( !m_manualEmbeddingState.inProgress ); + if( m_manualEmbeddingState.done && m_manualEmbeddingState.model == model ) return; + + const uint64_t hash = XXH3_64bits( m_manual->data(), m_manual->size() ); + auto cache = GetCachePath( model.c_str() ); + + try + { + m_manualEmbeddings = std::make_unique( cache, hash ); + m_manualEmbeddingState = { .model = model, .done = true }; + } + catch( std::exception& ) {} +} + void TracyLlmTools::BuildManualEmbeddings( const std::string& model, TracyLlmApi& api ) { std::unique_lock lock( m_lock ); @@ -246,19 +263,7 @@ void TracyLlmTools::BuildManualEmbeddings( const std::string& model, TracyLlmApi void TracyLlmTools::ManualEmbeddingsWorker( TracyLlmApi& api ) { const uint64_t hash = XXH3_64bits( m_manual->data(), m_manual->size() ); - auto cache = GetCachePath( m_manualEmbeddingState.model.c_str() ); - try - { - m_manualEmbeddings = std::make_unique( cache, hash ); - - std::lock_guard lock( m_lock ); - m_manualEmbeddingState.inProgress = false; - m_manualEmbeddingState.done = true; - - return; - } - catch( std::exception& ) {} std::unique_lock lock( m_lock ); if( m_cancel ) diff --git a/profiler/src/profiler/TracyLlmTools.hpp b/profiler/src/profiler/TracyLlmTools.hpp index c0eae6c6..cd365913 100644 --- a/profiler/src/profiler/TracyLlmTools.hpp +++ b/profiler/src/profiler/TracyLlmTools.hpp @@ -41,6 +41,7 @@ public: std::string GetCurrentTime() const; [[nodiscard]] EmbeddingState GetManualEmbeddingsState() const; + void SelectManualEmbeddings( const std::string& model ); void BuildManualEmbeddings( const std::string& model, TracyLlmApi& api ); void CancelManualEmbeddings();