diff --git a/sources/Session/SessionManager.cpp b/sources/Session/SessionManager.cpp index 7b61810..98b3f6c 100644 --- a/sources/Session/SessionManager.cpp +++ b/sources/Session/SessionManager.cpp @@ -18,7 +18,10 @@ namespace QodeAssist { SessionManager::SessionManager(AgentFactory *agentFactory, QObject *parent) : QObject(parent) , m_agentFactory(agentFactory) -{} +{ + if (m_agentFactory) + connect(m_agentFactory, &AgentFactory::agentsChanged, this, &SessionManager::flushPool); +} SessionManager::~SessionManager() = default; @@ -101,7 +104,7 @@ Session *SessionManager::acquire(const QString &agentName, QString *errorOut) auto &bucket = m_pool[agentName]; while (!bucket.isEmpty()) { QPointer pooled = bucket.takeLast(); - if (pooled && pooled->isValid()) { + if (pooled && pooled->isValid() && pooledAgentMatchesCurrent(pooled, agentName)) { resetSession(pooled); m_sessions.append(pooled); return pooled.data(); @@ -154,6 +157,32 @@ void SessionManager::resetSession(Session *session) } } +bool SessionManager::pooledAgentMatchesCurrent(Session *session, const QString &agentName) const +{ + if (!m_agentFactory) + return true; + Agent *agent = session ? session->agent() : nullptr; + if (!agent) + return false; + const AgentConfig *current = m_agentFactory->configByName(agentName); + if (!current) + return false; + const AgentConfig &snapshot = agent->config(); + return snapshot.model == current->model + && snapshot.providerInstance == current->providerInstance; +} + +void SessionManager::flushPool() +{ + for (auto &bucket : m_pool) { + for (const QPointer &pooled : bucket) { + if (pooled) + pooled->deleteLater(); + } + } + m_pool.clear(); +} + void SessionManager::removeSession(Session *session) { if (!session) diff --git a/sources/Session/SessionManager.hpp b/sources/Session/SessionManager.hpp index f6842c5..d5344a7 100644 --- a/sources/Session/SessionManager.hpp +++ b/sources/Session/SessionManager.hpp @@ -52,6 +52,9 @@ signals: private: void resetSession(Session *session); + void flushPool(); + [[nodiscard]] bool pooledAgentMatchesCurrent( + Session *session, const QString &agentName) const; static constexpr int kMaxPooledPerAgent = 2; diff --git a/sources/agents/agents.qrc b/sources/agents/agents.qrc index b74c547..e06f541 100644 --- a/sources/agents/agents.qrc +++ b/sources/agents/agents.qrc @@ -18,6 +18,7 @@ ollama_chat_completion.toml ollama_base_fim.toml ollama_fim.toml + ollama_codellama_qml_fim.toml roles/qt-cpp-developer.md diff --git a/sources/agents/claude_completion.toml b/sources/agents/claude_completion.toml index 378df97..761e142 100644 --- a/sources/agents/claude_completion.toml +++ b/sources/agents/claude_completion.toml @@ -16,7 +16,7 @@ system_prompt = """ [body] max_tokens = 512 -temperature = 0 +temperature = 0.2 stop_sequences = [""] messages = """ [ diff --git a/sources/agents/ollama_chat_completion.toml b/sources/agents/ollama_chat_completion.toml index 89dd982..ed96e90 100644 --- a/sources/agents/ollama_chat_completion.toml +++ b/sources/agents/ollama_chat_completion.toml @@ -26,7 +26,6 @@ messages = """ [body.options] num_predict = 512 -temperature = 0 -num_ctx = 8192 +temperature = 0.2 keep_alive = "5m" -stop = [""] +stop = [""] \ No newline at end of file diff --git a/sources/agents/ollama_codellama_qml_fim.toml b/sources/agents/ollama_codellama_qml_fim.toml new file mode 100644 index 0000000..a8972ed --- /dev/null +++ b/sources/agents/ollama_codellama_qml_fim.toml @@ -0,0 +1,23 @@ +schema_version = 1 + +name = "Ollama CodeLlama QML FIM" +description = "Local Ollama FIM for the CodeLlama-13B QML fine-tune (raw passthrough Modelfile, suffix-first markers)." + +provider_instance = "Ollama (Native)" +endpoint = "/api/generate" + +model = "theqtcompany/codellama-7b-qml" +tags = ["completion", "ollama", "local", "fim", "qml"] + +[match] +file_patterns = ["*.qml"] + +[body] +prompt = """{{ tojson("" + ctx.suffix + "
" + ctx.prefix + "") }}"""
+
+[body.options]
+temperature    = 0
+top_p          = 1
+repeat_penalty = 1.05
+num_predict    = 500
+stop           = ["", "
", "
", "
", "< EOT >", "\\end", "", "", "##"] diff --git a/sources/agents/ollama_fim.toml b/sources/agents/ollama_fim.toml index bdfb205..25ebd9e 100644 --- a/sources/agents/ollama_fim.toml +++ b/sources/agents/ollama_fim.toml @@ -10,7 +10,4 @@ tags = ["completion", "ollama", "local", "fim"] [body.options] num_predict = 512 temperature = 0.2 -top_p = 0.9 -num_ctx = 8192 keep_alive = "5m" -stop = [""]