diff --git a/lua/gemini/api.lua b/lua/gemini/api.lua index d04885c..0de6338 100644 --- a/lua/gemini/api.lua +++ b/lua/gemini/api.lua @@ -38,8 +38,9 @@ local function make_request(prompt, context) -- Add conversation history to the request for _, message in ipairs(conversation_history) do table.insert(contents, { + role = message.role, parts = {{ - text = message.role .. ": " .. message.content + text = message.content }} }) end @@ -47,14 +48,16 @@ local function make_request(prompt, context) -- Add the current prompt if context then table.insert(contents, { + role = "user", parts = {{ - text = "Context:\n" .. context .. "\n\nUser: " .. prompt + text = "Context:\n" .. context .. "\n\nQuery: " .. prompt }} }) else table.insert(contents, { + role = "user", parts = {{ - text = "User: " .. prompt + text = prompt }} }) end @@ -96,7 +99,7 @@ end function M.get_response(prompt, context) -- Add user message to history table.insert(conversation_history, { - role = "User", + role = "user", content = prompt }) @@ -119,7 +122,7 @@ function M.get_response(prompt, context) local response_text = result.candidates[1].content.parts[1].text -- Add assistant response to history table.insert(conversation_history, { - role = "Assistant", + role = "model", content = response_text }) return response_text