diff --git a/README.md b/README.md index cef70b415..bec6411f3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Default setup configuration: prev = "[x", }, }, + history_dir = nil -- default to $project_root/.avante_chat_history } ``` @@ -134,6 +135,26 @@ The following key bindings are available for use with `avante.nvim`: - ]x — move to previous conflict - [x — move to next conflict +## Set up A Custom History Directory + +By default, `avante.nvim` stores chat history in the project root directory under the `.avante_chat_history` folder. To change the default directory, set the `history_dir` option in the configuration. + +```lua +{ + history_dir = "/path/to/your/history/directory" +} +``` + +the `history_dir` can also be set to a function that accept project root directory and return the history directory. + +```lua +{ + history_dir = function(project_root) + return project_root .. "/.avante_chat_history" + end +} +``` + ## Roadmap - **Enhanced AI Interactions**: Improve the depth of AI analysis and recommendations for more complex coding scenarios. diff --git a/lua/avante/ai_bot.lua b/lua/avante/ai_bot.lua index 921ab1223..275e051c6 100644 --- a/lua/avante/ai_bot.lua +++ b/lua/avante/ai_bot.lua @@ -154,7 +154,7 @@ end local function call_openai_api_stream(question, code_lang, code_content, on_chunk, on_complete) local api_key = os.getenv("OPENAI_API_KEY") - if not api_key then + if not api_key and config.get().provider == "openai" then error("OPENAI_API_KEY environment variable is not set") end diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 8d55518e9..b0a4073b2 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -38,6 +38,7 @@ local config = { prev = "[x", }, }, + history_dir = nil, -- default to $project_root/.avante_chat_history } function M.update(opts) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 9188a3471..7ae9cd11b 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -7,6 +7,7 @@ local config = require("avante.config") local ai_bot = require("avante.ai_bot") local api = vim.api local fn = vim.fn +local utils = require("avante.utils") local RESULT_BUF_NAME = "AVANTE_RESULT" local CONFLICT_BUF_NAME = "AVANTE_CONFLICT" @@ -227,9 +228,16 @@ end -- Function to get the chat history file path local function get_chat_history_file() + local history_dir = config.get().history_dir local project_root = get_project_root() + if history_dir == nil then + history_dir = Path:new(project_root, ".avante_chat_history") + elseif type(history_dir) == "function" then + history_dir = history_dir(project_root) + else + history_dir = Path:new(history_dir, fn.fnamemodify(project_root, ":~:."), ".avante_chat_history") + end local filename = get_chat_history_filename() - local history_dir = Path:new(project_root, ".avante_chat_history") return history_dir:joinpath(filename .. ".json") end