From d51742459c8e8c9da522d52087ab61870375200b Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Thu, 12 Dec 2024 20:39:22 +0100 Subject: [PATCH] feat: change default initial prompt, use git root for config file --- lua/chatgpt_nvim/config.lua | 20 +++++++++++++++++--- lua/chatgpt_nvim/init.lua | 10 +++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lua/chatgpt_nvim/config.lua b/lua/chatgpt_nvim/config.lua index d0cb85c..6e5f966 100644 --- a/lua/chatgpt_nvim/config.lua +++ b/lua/chatgpt_nvim/config.lua @@ -1,11 +1,25 @@ +-- lua/chatgpt_nvim/config.lua +-- Modified to load the config file from the git root of the currently opened file +-- If not in a git repository, fallback to current working directory + local M = {} local uv = vim.loop local ok_yaml, lyaml = pcall(require, "lyaml") +local function get_project_root() + -- Attempt to find git root + local git_root = vim.fn.systemlist('git rev-parse --show-toplevel') + if vim.v.shell_error == 0 and git_root and #git_root > 0 then + return git_root[1] + end + -- Fallback to current working directory if git root not found + return vim.fn.getcwd() +end + local function get_config_path() - local cwd = vim.fn.getcwd() - local config_path = cwd .. "/.chatgpt_config.yaml" + local root = get_project_root() + local config_path = root .. "/.chatgpt_config.yaml" return config_path end @@ -34,7 +48,7 @@ function M.load() end end return { - initial_prompt = "", + initial_prompt = " You are a coding assistant who receives a project’s context and user instructions. The user will provide a prompt, and you will return modifications to the project in a YAML structure. This YAML must have a top-level key named files, which should be a list of file changes. Each element in files must be a mapping with the keys path and content. The path should be the file path relative to the project’s root directory, and content should contain the new file content as a multiline string (using the YAML | literal style). Do not include additional commentary outside of the YAML.\n Here is the structure expected in your final answer:\n files:\n - path: \"relative/path/to/file1.ext\"\n content: |\n \n - path: \"relative/path/to/file2.ext\"\n content: |\n \n Based on the prompt and project context provided, you must only return the YAML structure shown above (with actual file paths and contents substituted in). Any file that should be created or modified must appear as one of the files entries. The content should contain the complete and final code for that file, reflecting all changes requested by the user.", directories = { "." }, } end diff --git a/lua/chatgpt_nvim/init.lua b/lua/chatgpt_nvim/init.lua index cdd1a2a..1fe3943 100644 --- a/lua/chatgpt_nvim/init.lua +++ b/lua/chatgpt_nvim/init.lua @@ -1,3 +1,4 @@ +-- lua/chatgpt_nvim/init.lua local M = {} local context = require('chatgpt_nvim.context') @@ -39,11 +40,18 @@ function M.run_chatgpt_command() local current_file_content, current_file_path = context.get_current_file() local readme_content = context.get_readme_content() + -- Make the prompt more readable for the O1 model: + -- 1. Include initial prompt and user input at the start. + -- 2. Provide a clear project structure section. + -- 3. Clearly label the files section. + -- 4. The file_sections already include <<>> blocks for clarity.\n" } table.insert(sections, file_sections)