mirror of
https://github.com/wolfpld/tracy.git
synced 2026-08-24 20:18:21 +00:00
Automatically load embeddings when already calculated.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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<TracyLlmEmbeddings>( 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<TracyLlmEmbeddings>( 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 )
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user