An open API service indexing awesome lists of open source software.

https://github.com/mhd-gdev/genlms.nvim

A neovim plugin for using local LLMs with LMStudio server.
https://github.com/mhd-gdev/genlms.nvim

ai lms lmstudio neovim neovim-plugins plugin

Last synced: 4 months ago
JSON representation

A neovim plugin for using local LLMs with LMStudio server.

Awesome Lists containing this project

README

          

# genlms.nvim

Generate text using local LLMs with customizable prompts

![Local LLMs in Neovim: genlms.nvim](/genlms.png)

## Requires

- [LMStudio](https://lmstudio.ai) with any local model (GGUF models are recommended)
- [Curl](https://curl.se/)

## Install

Install with your favorite plugin manager, e.g. [lazy.nvim](https://github.com/folke/lazy.nvim)

Example with Lazy

```lua
-- Custom Parameters (with defaults)
{
"MHD-GDev/genlms.nvim",
dependencies = {
"nvim-lualine/lualine.nvim",
},
config = function()
require("genlms").setup({
quit_map = "q",
retry_map = "",
accept_map = "",
host = "localhost",
port = "1234",
display_mode = "split",
show_prompt = true,
show_model = true,
no_auto_close = false,
json_response = true,
result_filetype = "markdown",
debug = false,
})

-- Key mappings (Change as you like)
vim.keymap.set({ "n", "v" }, "]", ":Genlms")
vim.keymap.set("n", "ga", "Genlms Ask", { noremap = true })
vim.keymap.set("n", "gc", "Genlms Chat", { noremap = true })
vim.keymap.set("n", "gg", "Genlms Generate", { noremap = true })
vim.keymap.set("v", "gD", ":'<,'>Genlms Document_Code", { noremap = true })
vim.keymap.set("v", "gC", ":'<,'>Genlms Change", { noremap = true })
vim.keymap.set("v", "ge", ":'<,'>Genlms Enhance_Code", { noremap = true })
vim.keymap.set("v", "gR", ":'<,'>Genlms Review_Code", { noremap = true })
vim.keymap.set("v", "gs", ":'<,'>Genlms Summarize", { noremap = true })
vim.keymap.set("v", "ga", ":'<,'>Genlms Ask", { noremap = true })
vim.keymap.set("v", "gx", ":'<,'>Genlms Fix_Code", { noremap = true })
vim.keymap.set("n", "gl", "GenLoadModel", { noremap = true })
vim.keymap.set("n", "gu", "GenUnloadModel", { noremap = true })
end,
},
```

## Usage

Use command `Genlms` to generate text based on predefined and customizable prompts.

Example key maps:

```lua
vim.keymap.set({ 'n', 'v' }, ']', ':Genlms')
```

You can also directly invoke it with one of the [predefined prompts](./lua/genlms/prompts.lua) or your custom prompts:

```lua
vim.keymap.set('v', ']', ':Genlms Enhance_Grammar_Spelling')
```

After a conversation begins, the entire context is sent to the LLM. That allows you to ask follow-up questions with

```lua
:Genlms Chat
```

and once the window is closed, you start with a fresh conversation.

For prompts which don't automatically replace the previously selected text (`replace = false`), you can replace the selected text with the generated output with ``.

### Note:
To use genlms you need to load or unload models with these commands ```:GenUnloadModel``` and ```:GenLoadModel``` .

##### Models:

- You can downlaod models from [Hugingface](https://huggingface.co/models)

## Custom Prompts

[All prompts](./lua/genlms/prompts.lua) are defined in `require('genlms').prompts`, you can enhance or modify them.

Example:

````lua
require('genlms').prompts['Elaborate_Text'] = {
prompt = "Elaborate the following text:\n$text",
replace = true
}
require('genlms').prompts['Fix_Code'] = {
prompt = "Fix the following code. Only output the result in format ```$filetype\n...\n```:\n```$filetype\n$text\n```",
replace = true,
extract = "```$filetype\n(.-)```"
}
````

You can use the following properties per prompt:

- `prompt`: (string | function) Prompt either as a string or a function which should return a string. The result can use the following placeholders:
- `$text`: Visually selected text or the content of the current buffer
- `$filetype`: File type of the buffer (e.g. `javascript`)
- `$input`: Additional user input
- `$register`: Value of the unnamed register (yanked text)
- `replace`: `true` if the selected text shall be replaced with the generated output
- `extract`: Regular expression used to extract the generated result
- `model`: The model to use, default: `local-model`

## Tip

User selections can be delegated to [Telescope](https://github.com/nvim-telescope/telescope.nvim) with [telescope-ui-select](https://github.com/nvim-telescope/telescope-ui-select.nvim).

## Dev notes:

- This project was inspired by [gen.nvim](https://github.com/David-Kunz/gen.nvim), which laid the foundation for this version.
- For more information, see the [original project](https://github.com/David-Kunz/gen.nvim).
- We would like to express our gratitude to the original authors and contributors who made this project possible.