From 49f28affbf91f01103f5bf8353d2579a4f605ae8 Mon Sep 17 00:00:00 2001 From: Jordi Been Date: Mon, 11 Aug 2025 00:45:00 +0200 Subject: [PATCH 1/5] add support for ollama's direct /api/chat processing --- lua/gp/config.lua | 2 +- lua/gp/dispatcher.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/gp/config.lua b/lua/gp/config.lua index 43cf729..b4700d3 100644 --- a/lua/gp/config.lua +++ b/lua/gp/config.lua @@ -49,7 +49,7 @@ local config = { }, ollama = { disable = true, - endpoint = "http://localhost:11434/v1/chat/completions", + endpoint = "http://localhost:11434/api/chat", secret = "dummy_secret", }, lmstudio = { diff --git a/lua/gp/dispatcher.lua b/lua/gp/dispatcher.lua index e977d1d..58c8f23 100644 --- a/lua/gp/dispatcher.lua +++ b/lua/gp/dispatcher.lua @@ -270,6 +270,15 @@ local query = function(buf, provider, payload, handler, on_exit, callback) end end + if qt.provider == "ollama" then + if line:match('"message":') and line:match('"content":') then + local success, decoded = pcall(vim.json.decode, line) + if success and decoded.message and decoded.message.content then + content = decoded.message.content + end + end + end + if content and type(content) == "string" then qt.response = qt.response .. content @@ -391,6 +400,9 @@ local query = function(buf, provider, payload, handler, on_exit, callback) "api-key: " .. bearer, } endpoint = render.template_replace(endpoint, "{{model}}", payload.model) + elseif provider == "ollama" then + -- Ollama local API typically doesn't require authentication + headers = {} else -- default to openai compatible headers headers = { "-H", From f8a6c87be5035b0cc166fa59a020640e7ab90d86 Mon Sep 17 00:00:00 2001 From: Jordi Been Date: Mon, 11 Aug 2025 00:50:47 +0200 Subject: [PATCH 2/5] add support for think and options parameters --- lua/gp/dispatcher.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lua/gp/dispatcher.lua b/lua/gp/dispatcher.lua index 58c8f23..09038d2 100644 --- a/lua/gp/dispatcher.lua +++ b/lua/gp/dispatcher.lua @@ -161,6 +161,41 @@ D.prepare_payload = function(messages, model, provider) return payload end + if provider == "ollama" then + local payload = { + model = model.model, + stream = true, + messages = messages, + } + + if model.think ~= nil then + payload.think = model.think + end + + local options = {} + if model.temperature then + options.temperature = math.max(0, math.min(2, model.temperature)) + end + if model.top_p then + options.top_p = math.max(0, math.min(1, model.top_p)) + end + if model.min_p then + options.min_p = math.max(0, math.min(1, model.min_p)) + end + if model.num_ctx then + options.num_ctx = model.num_ctx + end + if model.top_k then + options.top_k = model.top_k + end + + if next(options) then + payload.options = options + end + + return payload + end + local output = { model = model.model, stream = true, From b4b65bfbbb0068b419a147a4b061c9f2b0551f58 Mon Sep 17 00:00:00 2001 From: Jordi Been Date: Mon, 11 Aug 2025 00:51:37 +0200 Subject: [PATCH 3/5] add 'ChatQwen3-8B' as default agent (thinking-disabled qwen model) --- lua/gp/config.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lua/gp/config.lua b/lua/gp/config.lua index b4700d3..ab54aea 100644 --- a/lua/gp/config.lua +++ b/lua/gp/config.lua @@ -196,6 +196,19 @@ local config = { -- system prompt (use this to specify the persona/role of the AI) system_prompt = "You are a general AI assistant.", }, + { + provider = "ollama", + name = "ChatQwen3-8B", + chat = true, + command = false, + -- string with model name or table with model name and parameters + model = { + model = "qwen3:8b", + think = false, -- toggle thinking in ollama's "thinkings" models + }, + -- system prompt (use this to specify the persona/role of the AI) + system_prompt = "You are a general AI assistant.", + }, { provider = "lmstudio", name = "ChatLMStudio", From 7933b33a4ac39213ba66aa82cb9f01a358f3782d Mon Sep 17 00:00:00 2001 From: Jordi Been Date: Mon, 11 Aug 2025 00:55:17 +0200 Subject: [PATCH 4/5] remove comment --- lua/gp/dispatcher.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/gp/dispatcher.lua b/lua/gp/dispatcher.lua index 09038d2..960ed31 100644 --- a/lua/gp/dispatcher.lua +++ b/lua/gp/dispatcher.lua @@ -436,7 +436,6 @@ local query = function(buf, provider, payload, handler, on_exit, callback) } endpoint = render.template_replace(endpoint, "{{model}}", payload.model) elseif provider == "ollama" then - -- Ollama local API typically doesn't require authentication headers = {} else -- default to openai compatible headers headers = { From 2bc73d7c0033bce4faac57f84ca87e52324667a9 Mon Sep 17 00:00:00 2001 From: Jordi Been Date: Mon, 11 Aug 2025 01:07:37 +0200 Subject: [PATCH 5/5] clarify comment --- lua/gp/config.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gp/config.lua b/lua/gp/config.lua index ab54aea..b94953c 100644 --- a/lua/gp/config.lua +++ b/lua/gp/config.lua @@ -204,7 +204,7 @@ local config = { -- string with model name or table with model name and parameters model = { model = "qwen3:8b", - think = false, -- toggle thinking in ollama's "thinkings" models + think = false, -- toggle thinking mode for Ollama's thinking models }, -- system prompt (use this to specify the persona/role of the AI) system_prompt = "You are a general AI assistant.",