debug completion

This commit is contained in:
Jonas Widen 2025-03-17 07:55:42 +01:00
parent a69d1c70b1
commit f34bd77732

View File

@ -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