Restore chat history
This commit is contained in:
parent
c41e4fe9dd
commit
e36c7539d7
@ -1,10 +1,8 @@
|
|||||||
local config = require("gemini.config")
|
local config = require("gemini.config")
|
||||||
local http = require("gemini.http")
|
local http = require("gemini.http")
|
||||||
|
local chat = require("gemini.chat") -- Add chat module
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Store conversation history
|
|
||||||
local conversation_history = {}
|
|
||||||
|
|
||||||
local function get_api_key()
|
local function get_api_key()
|
||||||
return vim.g.gemini_api_key or os.getenv("GEMINI_API_KEY")
|
return vim.g.gemini_api_key or os.getenv("GEMINI_API_KEY")
|
||||||
end
|
end
|
||||||
@ -12,7 +10,7 @@ end
|
|||||||
local function create_contents(prompt, context)
|
local function create_contents(prompt, context)
|
||||||
local contents = {}
|
local contents = {}
|
||||||
|
|
||||||
for _, message in ipairs(conversation_history) do
|
for _, message in ipairs(chat.get_conversation_history()) do
|
||||||
table.insert(contents, {
|
table.insert(contents, {
|
||||||
role = message.role,
|
role = message.role,
|
||||||
parts = {{text = message.content}}
|
parts = {{text = message.content}}
|
||||||
@ -35,7 +33,7 @@ local function create_contents(prompt, context)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function store_message(role, content)
|
local function store_message(role, content)
|
||||||
table.insert(conversation_history, {role = role, content = content})
|
chat.add_message(role, content)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function handle_response(result, callback)
|
local function handle_response(result, callback)
|
||||||
@ -91,7 +89,7 @@ function M.get_response(prompt, context, callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.clear_conversation()
|
function M.clear_conversation()
|
||||||
conversation_history = {}
|
chat.clear() -- This will clear both the buffer and conversation history
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user