Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/StubbornVegeta/llm.nvim
Free large language model (LLM) support for Neovim.
https://github.com/StubbornVegeta/llm.nvim
chatgpt llm neovim neovim-plugin nvim nvim-lua
Last synced: 2 months ago
JSON representation
Free large language model (LLM) support for Neovim.
- Host: GitHub
- URL: https://github.com/StubbornVegeta/llm.nvim
- Owner: StubbornVegeta
- Created: 2024-08-17T14:08:38.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-08-24T06:31:30.000Z (3 months ago)
- Last Synced: 2024-08-24T16:26:23.666Z (3 months ago)
- Topics: chatgpt, llm, neovim, neovim-plugin, nvim, nvim-lua
- Language: Lua
- Homepage:
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-neovim - StubbornVegeta/llm.nvim - Free large language model (LLM) support, provides commands to interact with LLM. (AI / (requires Neovim 0.5))
README
# llm.nvim
Free large language model (LLM) support for Neovim based on [cloudflare](https://dash.cloudflare.com/).
You need sign up on [cloudflare](https://dash.cloudflare.com/) and get your account and API key. Then you will find all [models](https://developers.cloudflare.com/workers-ai/models/) on cloudflare, where the models labeled as beta are free.
## Screenshots
## Installation
Set `ACCOUNT` and `LLM_KEY` in your zshrc or bashrc
```sh
export ACCOUNT=xxxxxxxx
export LLM_KEY=********
```- lazy.nvim
```lua
{
"StubbornVegeta/llm.nvim",
dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" },
cmd = { "LLMSesionToggle", "LLMSelectedTextHandler" },
config = function()
require("llm").setup()
end,
keys = {
{ "ac", mode = "n", "LLMSessionToggle" },
{ "ae", mode = "v", "LLMSelectedTextHandler 请解释下面这段代码" },
{ "t", mode = "x", "LLMSelectedTextHandler 英译汉" },
},
},
```## Default Configuration
- floating window
| window | key | mode | desc |
| ------------ | ------------ | -------- | ----------------------- |
| Input | `ctrl+g` | `i` | submit your question |
| Input | `ctrl+c` | `i` | cancel dialog response |
| Input | `ctrl+r` | `i` | Rerespond to the dialog |
| Input | `ctrl+j` | `i` | select the next session history |
| Input | `ctrl+k` | `i` | select the previous session history |
| Output+Input | `ac` | `n` | toggle session |
| Output+Input | `` | `n` | close session |- split window
| window | key | mode | desc |
| ------------ | ------------ | -------- | ----------------------- |
| Input | `` | `n` | submit your question |
| Output | `i` | `n` | open the input box |
| Output | `ctrl+c` | `n` | cancel dialog response |
| Output | `ctrl+r` | `n` | Rerespond to the dialog |## Configuration
`llm.nvim` comes with the following defaults, you can override them by passing config as setup param.
https://github.com/StubbornVegeta/llm.nvim/blob/c7c546aef0e12bf645843a6fcb83f27b2987f75e/lua/llm/config.lua#L26-L158
### Example Configuration
```lua
{
"StubbornVegeta/llm.nvim",
dependencies = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" },
cmd = { "LLMSesionToggle", "LLMSelectedTextHandler" },
config = function()
require("llm").setup({
prompt = "请用中文回答",
max_tokens = 512,
model = "@cf/qwen/qwen1.5-14b-chat-awq",
prefix = {
user = { text = "😃 ", hl = "Title" },
assistant = { text = "⚡ ", hl = "Added" },
},save_session = true, -- if false, history box will not be showed
max_history = 15, -- max number of history
history_path = "/tmp/history", -- where to save historyinput_box_opts = {
relative = "editor",
position = {
row = "85%",
col = 15,
},
size = {
height = "5%",
width = 120,
},enter = true,
focusable = true,
zindex = 50,
border = {
style = "rounded",
text = {
top = " Enter Your Question ",
top_align = "center",
},
},
win_options = {
-- set window transparency
winblend = 20,
-- set window highlight
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
},
},
output_box_opts = {
style = "float", -- right | left | above | below | float
relative = "editor",
position = {
row = "35%",
col = 15,
},
size = {
height = "65%",
width = 90,
},
enter = true,
focusable = true,
zindex = 20,
border = {
style = "rounded",
text = {
top = " Preview ",
top_align = "center",
},
},
win_options = {
winblend = 20,
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
},
},history_box_opts = {
relative = "editor",
position = {
row = "35%",
col = 108,
},
size = {
height = "65%",
width = 27,
},
zindex = 70,
enter = false,
focusable = false,
border = {
style = "rounded",
text = {
top = " History ",
top_align = "center",
},
},
win_options = {
winblend = 20,
winhighlight = "Normal:Normal,FloatBorder:FloatBorder",
},
},-- LLMSelectedTextHandler windows options
popwin_opts = {
relative = "cursor",
position = {
row = -7,
col = 20,
},
size = {
width = "50%",
height = 15,
},
enter = true,
border = {
style = "rounded",
text = {
top = " Explain ",
},
},
},-- stylua: ignore
keys = {
-- The keyboard mapping for the input window.
["Input:Submit"] = { mode = "n", key = "" },
["Input:Cancel"] = { mode = "n", key = "" },
["Input:Resend"] = { mode = "n", key = "" },-- only works when "save_session = true"
["Input:HistoryNext"] = { mode = "n", key = "" },
["Input:HistoryPrev"] = { mode = "n", key = "" },-- The keyboard mapping for the output window in "split" style.
["Output:Ask"] = { mode = "n", key = "i" },
["Output:Cancel"] = { mode = "n", key = "" },
["Output:Resend"] = { mode = "n", key = "" },-- The keyboard mapping for the output and input windows in "float" style.
["Session:Toggle"] = { mode = "n", key = "ac" },
["Session:Close"] = { mode = "n", key = "" },
},
})
end,
keys = {
{ "ac", mode = "n", "LLMSessionToggle" },
{ "ae", mode = "v", "LLMSelectedTextHandler 请解释下面这段代码" },
{ "t", mode = "x", "LLMSelectedTextHandler 英译汉" },
},
},
```
Finally, here is my personal configuration for reference.https://github.com/StubbornVegeta/.lazyvim/blob/ec6ba2f6610cf0f9645543ea2a43882272870088/lua/plugins/coding.lua#L114-L158