Skip to content

Commit

Permalink
Chat AI: added a drop down to the chat window for quickly swithching …
Browse files Browse the repository at this point in the history
…between models
  • Loading branch information
eranif committed Aug 15, 2024
1 parent bb9c89b commit fba63df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
31 changes: 30 additions & 1 deletion ChatAI/ChatAIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent, ChatAIConfig& config)

m_toolbar->AddTool(wxID_PREFERENCES, _("Settings"), images->LoadBitmap("cog", 24));
m_toolbar->AddTool(wxID_CLEAR, _("Clear content"), images->LoadBitmap("clear", 24));
m_activeModel = new wxChoice(m_toolbar, wxID_ANY);
m_toolbar->AddControl(m_activeModel);
PopulateModels();

m_toolbar->SetToolBitmapSize(FromDIP(wxSize(24, 24)));
m_toolbar->Realize();

Expand All @@ -35,6 +39,7 @@ ChatAIWindow::ChatAIWindow(wxWindow* parent, ChatAIConfig& config)
m_stcInput->Bind(wxEVT_KEY_DOWN, &ChatAIWindow::OnKeyDown, this);
Bind(wxEVT_MENU, &ChatAIWindow::OnSettings, this, wxID_PREFERENCES);
Bind(wxEVT_MENU, &ChatAIWindow::OnClear, this, wxID_CLEAR);
m_activeModel->Bind(wxEVT_CHOICE, &ChatAIWindow::OnActiveModelChanged, this);
}

ChatAIWindow::~ChatAIWindow()
Expand Down Expand Up @@ -120,7 +125,9 @@ void ChatAIWindow::OnClear(wxCommandEvent& event)
void ChatAIWindow::ShowSettings()
{
ChatAISettingsDlg dlg(this, m_config);
dlg.ShowModal();
if (dlg.ShowModal() == wxID_OK) {
PopulateModels();
}
}

void ChatAIWindow::OnChatAIStarted(clCommandEvent& event)
Expand Down Expand Up @@ -160,3 +167,25 @@ void ChatAIWindow::OnStop(wxCommandEvent& event)
clCommandEvent event_stop{ wxEVT_CHATAI_STOP };
EventNotifier::Get()->AddPendingEvent(event_stop);
}

void ChatAIWindow::PopulateModels()
{
m_activeModel->Clear();
auto models = m_config.GetModels();
for (auto model : models) {
m_activeModel->Append(model->m_name);
}

auto activeModelName = m_config.GetSelectedModel() ? m_config.GetSelectedModel()->m_name : wxString();
if (!activeModelName.empty()) {
m_activeModel->SetStringSelection(activeModelName);
}
}

void ChatAIWindow::OnActiveModelChanged(wxCommandEvent& event)
{
wxUnusedVar(event);
wxString activeModel = m_activeModel->GetStringSelection();
m_config.SetSelectedModelName(activeModel);
m_config.Save();
}
3 changes: 3 additions & 0 deletions ChatAI/ChatAIWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ class ChatAIWindow : public AssistanceAIChatWindowBase
void OnChatAIOutput(clCommandEvent& event);
void OnChatAIStderr(clCommandEvent& event);
void OnChatAITerminated(clCommandEvent& event);
void PopulateModels();
void OnActiveModelChanged(wxCommandEvent& event);

private:
ChatAIConfig& m_config;
bool m_llamaCliRunning = false;
wxChoice* m_activeModel = nullptr;
};

wxDECLARE_EVENT(wxEVT_CHATAI_SEND, clCommandEvent);
Expand Down

0 comments on commit fba63df

Please sign in to comment.