Fixed issues

This commit is contained in:
Jonas Widen 2025-03-16 14:46:15 +01:00
parent 2aeaed13b8
commit acfa74de7b

View File

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