diff --git a/lua/gemini/api.lua b/lua/gemini/api.lua index aab4285..b5d2f10 100644 --- a/lua/gemini/api.lua +++ b/lua/gemini/api.lua @@ -1,10 +1,8 @@ local config = require("gemini.config") local http = require("gemini.http") +local chat = require("gemini.chat") -- Add chat module local M = {} --- Store conversation history -local conversation_history = {} - local function get_api_key() return vim.g.gemini_api_key or os.getenv("GEMINI_API_KEY") end @@ -12,7 +10,7 @@ end local function create_contents(prompt, context) local contents = {} - for _, message in ipairs(conversation_history) do + for _, message in ipairs(chat.get_conversation_history()) do table.insert(contents, { role = message.role, parts = {{text = message.content}} @@ -35,7 +33,7 @@ local function create_contents(prompt, context) end local function store_message(role, content) - table.insert(conversation_history, {role = role, content = content}) + chat.add_message(role, content) end local function handle_response(result, callback) @@ -91,7 +89,7 @@ function M.get_response(prompt, context, callback) end function M.clear_conversation() - conversation_history = {} + chat.clear() -- This will clear both the buffer and conversation history end return M