From f34bd77732e5a0e29e94b878133af724caae90d4 Mon Sep 17 00:00:00 2001 From: Jonas Widen Date: Mon, 17 Mar 2025 07:55:42 +0100 Subject: [PATCH] debug completion --- lua/gemini/api.lua | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lua/gemini/api.lua b/lua/gemini/api.lua index b8f0b70..e1bf5e8 100644 --- a/lua/gemini/api.lua +++ b/lua/gemini/api.lua @@ -87,17 +87,13 @@ function M.get_response(prompt, context, callback) return end - store_message("user", prompt) - - local contents = create_contents(prompt, context) - - -- Validate contents before sending - if not contents or #contents == 0 then - vim.schedule(function() - callback(nil, "Failed to create request contents") - end) - return - end + -- Create the request content + local contents = { + { + role = "user", + parts = {{text = context and (context .. "\n\n" .. prompt) or prompt}} + } + } local payload = vim.json.encode({ contents = contents, @@ -118,9 +114,12 @@ function M.get_response(prompt, context, callback) local request = http.Request.new(url, payload) request:execute(function(result, error) if error then - callback(nil, error) + vim.schedule(function() + callback(nil, "HTTP Error: " .. error) + end) return end + handle_response(result, callback) end) end