Skip to content

Commit

Permalink
Update configuration and plugin setup
Browse files Browse the repository at this point in the history
- Refactor `chatgpt.sh` to dynamically read API host, key, and model from configuration files.
- Update `lazy-lock.json` with the latest plugin commits.
- Enhance `copilot.lua` to read API host and model from files, improve error handling, and update Avante setup.
- Add new `symboltable.lua` plugin configuration for `aerial.nvim` with key mapping for toggling.
- Modify `treesitter.lua` key mappings for parameter swapping.
  • Loading branch information
wongsingfo committed Dec 20, 2024
1 parent 60fca71 commit 8efa159
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 46 deletions.
15 changes: 4 additions & 11 deletions chatgpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,10 @@
set -e
set -o pipefail

# API_HOST=api.openai.com
# API_HOST=api.anthropic.com
# API_HOST=api.deepseek.com
# API_HOST=api.gptsapi.net
# API_HOST=api.xiaoai.plus
API_HOST=api.lingyiwanwu.com
API_KEY=$(cat $HOME/.llmkeys/YI_KEY)

# MODEL="deepseek-coder"
# MODEL="gpt-4o-mini"
MODEL="yi-lightning"
CONFIG_DIR=$HOME/.llmkeys
API_HOST=$(cat $CONFIG_DIR/HOST)
API_KEY=$(cat $CONFIG_DIR/$API_HOST)
MODEL=$(cat $CONFIG_DIR/MODEL)

TMP_FILE=/tmp/chatgpt-input.txt
PROMPT_SYSTEM="You are a large language model. Answer as concisely as possible."
Expand Down
31 changes: 16 additions & 15 deletions stow-dotfiles/nvim/.config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
{
"avante.nvim": { "branch": "main", "commit": "2863473bbf575bd7ae3836ed385602515e0fab12" },
"aerial.nvim": { "branch": "master", "commit": "fd7fbe36772d7a955815c90ff9b58523bfdb410d" },
"avante.nvim": { "branch": "main", "commit": "01e05a538b4b7f20fb922016d72be8c42d400b0e" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"cmp-nvim-lsp": { "branch": "main", "commit": "99290b3ec1322070bcfb9e846450a46f6efa50f0" },
"cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"codeium.nvim": { "branch": "main", "commit": "dddaee0d1e9a1d0bcaea66f08a8103b3cdf26604" },
"codeium.nvim": { "branch": "main", "commit": "27d2b1ce8c7ba14dbf6e4504bdea8e5548be5476" },
"dressing.nvim": { "branch": "master", "commit": "fc78a3ca96f4db9f8893bb7e2fd9823e0780451b" },
"fidget.nvim": { "branch": "main", "commit": "e2a175c2abe2d4f65357da1c98c59a5cfb2b543f" },
"gitsigns.nvim": { "branch": "main", "commit": "ac5aba6dce8c06ea22bea2c9016f51a2dbf90dc7" },
"fidget.nvim": { "branch": "main", "commit": "9238947645ce17d96f30842e61ba81147185b657" },
"gitsigns.nvim": { "branch": "main", "commit": "5f808b5e4fef30bd8aca1b803b4e555da07fc412" },
"gruvbox": { "branch": "master", "commit": "f1ecde848f0cdba877acb0c740320568252cc482" },
"guess-indent.nvim": { "branch": "main", "commit": "6cd61f7a600bb756e558627cd2e740302c58e32d" },
"lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" },
"lspkind.nvim": { "branch": "master", "commit": "a700f1436d4a938b1a1a93c9962dc796afbaef4d" },
"lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" },
"lspkind.nvim": { "branch": "master", "commit": "d79a1c3299ad0ef94e255d045bed9fa26025dab6" },
"marks.nvim": { "branch": "master", "commit": "bb25ae3f65f504379e3d08c8a02560b76eaf91e8" },
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
"nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" },
"nui.nvim": { "branch": "main", "commit": "53e907ffe5eedebdca1cd503b00aa8692068ca46" },
"nvim-bqf": { "branch": "main", "commit": "1b24dc6050c34e8cd377b6b4cd6abe40509e0187" },
"nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" },
"nvim-lspconfig": { "branch": "master", "commit": "f012c1b176f0e3c71f40eb309bdec0316689462e" },
"nvim-cmp": { "branch": "main", "commit": "b555203ce4bd7ff6192e759af3362f9d217e8c89" },
"nvim-lspconfig": { "branch": "master", "commit": "040001d85e9190a904d0e35ef5774633e14d8475" },
"nvim-osc52": { "branch": "main", "commit": "04cfaba1865ae5c53b6f887c3ca7304973824fb2" },
"nvim-treesitter": { "branch": "master", "commit": "c50981479e4271ec87c5a15ec991472bdec4f1b8" },
"nvim-treesitter-context": { "branch": "master", "commit": "1147c42cf9477701581d1eb31e1735969e21dd06" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "3e450cd85243da99dc23ebbf14f9c70e9a0c26a4" },
"nvim-web-devicons": { "branch": "master", "commit": "e87554285f581047b1bf236794b0eb812b444b87" },
"nvim-treesitter": { "branch": "master", "commit": "fa915a30c5cdf1d18129e9ef6ac2ee0fa799904f" },
"nvim-treesitter-context": { "branch": "master", "commit": "8fd989b6b457a448606b4a2e51f9161700f609a7" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "ad8f0a472148c3e0ae9851e26a722ee4e29b1595" },
"nvim-web-devicons": { "branch": "master", "commit": "0eb18da56e2ba6ba24de7130a12bcc4e31ad11cb" },
"playground": { "branch": "master", "commit": "ba48c6a62a280eefb7c85725b0915e021a1a0749" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"tcomment_vim": { "branch": "master", "commit": "48ab639a461d9b8344f7fee06cb69b4374863b13" },
"vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" },
"which-key.nvim": { "branch": "main", "commit": "68e37e12913a66b60073906f5d3f14dee0de19f2" }
"which-key.nvim": { "branch": "main", "commit": "8ab96b38a2530eacba5be717f52e04601eb59326" }
}
52 changes: 34 additions & 18 deletions stow-dotfiles/nvim/.config/nvim/lua/plugins/copilot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,51 @@ return {
"MunifTanjim/nui.nvim",
},
config = function()
local openai_key_file = vim.fn.expand("$HOME/.llmkeys/YI_KEY")
-- Get the API host from the file
local host_file_path = vim.fn.expand("$HOME/.llmkeys/HOST")
local model_file_path = vim.fn.expand("$HOME/.llmkeys/MODEL")

require 'avante'.setup {
local function read_file_trim_whitespace(file_path)
local success, file = pcall(io.open, file_path, "r")
if success and file then
local content = file:read("*all"):gsub("%s+", "")
file:close()
return content
else
vim.notify("Failed to read file: " .. file_path, vim.log.levels.ERROR)
return nil
end
end

local api_host = read_file_trim_whitespace(host_file_path)
if not api_host then
return
end

local model = read_file_trim_whitespace(model_file_path) or "gpt-4o"
if not model then
return
end

local openai_key_file = vim.fn.expand("$HOME/.llmkeys/" .. api_host)

-- Setup Avante with OpenAI configuration using the model from the file
require('avante').setup {
provider = "openai",
openai = {
-- endpoint = "https://api.xiaoai.plus/v1",
endpoint = "https://api.lingyiwanwu.com/v1",
-- model = "claude-3-5-sonnet-20241022",
-- model = "gpt-4o-2024-08-06",
model = "yi-lightning",
endpoint = "https://" .. api_host .. '/v1',
model = model,
api_key_name = "cmd:cat " .. openai_key_file,
temperature = 0,
max_tokens = 4096,
},
hints = { enabled = false },
windows = {
wrap = true, -- similar to vim.o.wrap
position = "right", -- the position of the sidebar
width = 40, -- default % based on available width
sidebar_header = {
align = "center", -- left, center, right for title
rounded = false,
},
},
}

-- vim.api.nvim_set_hl(0, 'AvanteDiffAdd', { bg = "#002800" })
-- vim.api.nvim_set_hl(0, 'AvanteDiffText', { bg = "#280000" })
-- vim.api.nvim_set_hl(0, 'AvanteConflictIncoming', { bg = "#400000" })
-- vim.api.nvim_set_hl(0, 'AvanteConflictCurrent', { bg = "#280000" })
-- Set highlight groups for Avante conflicts
vim.api.nvim_set_hl(0, 'AvanteConflictIncoming', { bg = "#002800" })
vim.api.nvim_set_hl(0, 'AvanteConflictCurrent', { bg = "#280000" })
end
}
1 change: 1 addition & 0 deletions stow-dotfiles/nvim/.config/nvim/lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ require('lazy').setup {
require("plugins.cmp"),
require("plugins.colorscheme"),
require("plugins.copilot"),
require("plugins.symboltable"),
}
30 changes: 30 additions & 0 deletions stow-dotfiles/nvim/.config/nvim/lua/plugins/symboltable.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
return {
'stevearc/aerial.nvim',
-- Optional dependencies
dependencies = {
"nvim-treesitter/nvim-treesitter",
"nvim-tree/nvim-web-devicons"
},
config = function()
require("aerial").setup {
-- Set to false to display all symbols.
filter_kind = false,
-- filter_kind = {
-- -- Default
-- "Class",
-- "Constructor",
-- "Enum",
-- "Function",
-- "Interface",
-- "Module",
-- "Method",
-- "Struct",
--
-- -- Additional
-- -- To see all available values, see :help SymbolKind
-- "Variable",
-- },
}
vim.keymap.set("n", "<leader>gs", "<cmd>AerialToggle!<CR>")
end
}
4 changes: 2 additions & 2 deletions stow-dotfiles/nvim/.config/nvim/lua/plugins/treesitter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ local function setup_textobjects()
swap = {
enable = true,
swap_next = {
["<leader>gs"] = "@parameter.inner",
["<leader>g>"] = "@parameter.inner",
},
swap_previous = {
["<leader>gS"] = "@parameter.inner", },
["<leader>g<"] = "@parameter.inner", },
},
select = {
enable = true,
Expand Down

0 comments on commit 8efa159

Please sign in to comment.