mirror of
https://github.com/nix-community/nixvim.git
synced 2025-11-08 19:46:06 +01:00
plugins/ollama: migrate to mkNeovimPlugin
This commit is contained in:
parent
a68291151c
commit
9bdedc0510
3 changed files with 100 additions and 255 deletions
|
|
@ -1,232 +1,46 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
helpers,
|
|
||||||
config,
|
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
with lib;
|
lib.nixvim.plugins.mkNeovimPlugin {
|
||||||
let
|
name = "ollama";
|
||||||
cfg = config.plugins.ollama;
|
package = "ollama-nvim";
|
||||||
|
|
||||||
actionOptionType =
|
maintainers = [ lib.maintainers.GaetanLepage ];
|
||||||
with lib.types;
|
|
||||||
oneOf [
|
|
||||||
rawLua
|
|
||||||
(enum [
|
|
||||||
"display"
|
|
||||||
"replace"
|
|
||||||
"insert"
|
|
||||||
"display_replace"
|
|
||||||
"display_insert"
|
|
||||||
"display_prompt"
|
|
||||||
])
|
|
||||||
(submodule {
|
|
||||||
options = {
|
|
||||||
fn = helpers.mkNullOrStrLuaFnOr (enum [ false ]) ''
|
|
||||||
fun(prompt: table): Ollama.PromptActionResponseCallback
|
|
||||||
|
|
||||||
Example:
|
# TODO: introduced 2025-10-06
|
||||||
```lua
|
inherit (import ./deprecations.nix) deprecateExtraOptions optionsRenamedToSettings;
|
||||||
function(prompt)
|
|
||||||
-- This function is called when the prompt is selected
|
|
||||||
-- just before sending the prompt to the LLM.
|
|
||||||
-- Useful for setting up UI or other state.
|
|
||||||
|
|
||||||
-- Return a function that will be used as a callback
|
|
||||||
-- when a response is received.
|
|
||||||
---@type Ollama.PromptActionResponseCallback
|
|
||||||
return function(body, job)
|
|
||||||
-- body is a table of the json response
|
|
||||||
-- body.response is the response text received
|
|
||||||
|
|
||||||
-- job is the plenary.job object when opts.stream = true
|
|
||||||
-- job is nil otherwise
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
```
|
|
||||||
'';
|
|
||||||
|
|
||||||
opts = {
|
|
||||||
stream = helpers.defaultNullOpts.mkBool false ''
|
|
||||||
Whether to stream the response.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
in
|
|
||||||
{
|
|
||||||
meta.maintainers = [ maintainers.GaetanLepage ];
|
|
||||||
|
|
||||||
options.plugins.ollama = lib.nixvim.plugins.neovim.extraOptionsOptions // {
|
|
||||||
enable = mkEnableOption "ollama.nvim";
|
|
||||||
|
|
||||||
package = lib.mkPackageOption pkgs "ollama.nvim" {
|
|
||||||
default = [
|
|
||||||
"vimPlugins"
|
|
||||||
"ollama-nvim"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
model = helpers.defaultNullOpts.mkStr "mistral" ''
|
|
||||||
The default model to use.
|
|
||||||
'';
|
|
||||||
|
|
||||||
prompts =
|
|
||||||
let
|
|
||||||
promptOptions = {
|
|
||||||
prompt = mkOption {
|
|
||||||
type = with lib.types; maybeRaw str;
|
|
||||||
description = ''
|
|
||||||
The prompt to send to the model.
|
|
||||||
|
|
||||||
Replaces the following tokens:
|
|
||||||
- `$input`: The input from the user
|
|
||||||
- `$sel`: The currently selected text
|
|
||||||
- `$ftype`: The filetype of the current buffer
|
|
||||||
- `$fname`: The filename of the current buffer
|
|
||||||
- `$buf`: The contents of the current buffer
|
|
||||||
- `$line`: The current line in the buffer
|
|
||||||
- `$lnum`: The current line number in the buffer
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
inputLabel = helpers.defaultNullOpts.mkStr "> " ''
|
|
||||||
The label to use for an input field.
|
|
||||||
'';
|
|
||||||
|
|
||||||
action = helpers.mkNullOrOption actionOptionType ''
|
|
||||||
How to handle the output.
|
|
||||||
|
|
||||||
See [here](https://github.com/nomnivore/ollama.nvim/tree/main#actions) for more details.
|
|
||||||
|
|
||||||
Defaults to the value of `plugins.ollama.action`.
|
|
||||||
'';
|
|
||||||
|
|
||||||
model = helpers.mkNullOrStr ''
|
|
||||||
The model to use for this prompt.
|
|
||||||
|
|
||||||
Defaults to the value of `plugins.ollama.model`.
|
|
||||||
'';
|
|
||||||
|
|
||||||
extract =
|
|
||||||
helpers.defaultNullOpts.mkNullable (with lib.types; maybeRaw (either str (enum [ false ])))
|
|
||||||
"```$ftype\n(.-)```"
|
|
||||||
''
|
|
||||||
A `string.match` pattern to use for an Action to extract the output from the response
|
|
||||||
(Insert/Replace).
|
|
||||||
'';
|
|
||||||
|
|
||||||
options = helpers.mkNullOrOption (with types; attrsOf anything) ''
|
|
||||||
Additional model parameters, such as temperature, listed in the documentation for the [Modelfile](https://github.com/jmorganca/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values).
|
|
||||||
'';
|
|
||||||
|
|
||||||
system = helpers.mkNullOrStr ''
|
|
||||||
The SYSTEM instruction specifies the system prompt to be used in the Modelfile template,
|
|
||||||
if applicable.
|
|
||||||
(overrides what's in the Modelfile).
|
|
||||||
'';
|
|
||||||
|
|
||||||
format = helpers.defaultNullOpts.mkEnumFirstDefault [ "json" ] ''
|
|
||||||
The format to return a response in.
|
|
||||||
Currently the only accepted value is `"json"`.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
processPrompt =
|
|
||||||
prompt:
|
|
||||||
if isAttrs prompt then
|
|
||||||
{
|
|
||||||
inherit (prompt) prompt;
|
|
||||||
input_label = prompt.inputLabel;
|
|
||||||
inherit (prompt)
|
|
||||||
action
|
|
||||||
model
|
|
||||||
extract
|
|
||||||
options
|
|
||||||
system
|
|
||||||
format
|
|
||||||
;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
prompt;
|
|
||||||
in
|
|
||||||
mkOption {
|
|
||||||
type = with types; attrsOf (either (submodule { options = promptOptions; }) (enum [ false ]));
|
|
||||||
default = { };
|
|
||||||
apply = v: mapAttrs (_: processPrompt) v;
|
|
||||||
description = ''
|
|
||||||
A table of prompts to use for each model.
|
|
||||||
Default prompts are defined [here](https://github.com/nomnivore/ollama.nvim/blob/main/lua/ollama/prompts.lua).
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
action = helpers.defaultNullOpts.mkNullable actionOptionType "display" ''
|
|
||||||
How to handle prompt outputs when not specified by prompt.
|
|
||||||
|
|
||||||
See [here](https://github.com/nomnivore/ollama.nvim/tree/main#actions) for more details.
|
|
||||||
'';
|
|
||||||
|
|
||||||
url = helpers.defaultNullOpts.mkStr "http://127.0.0.1:11434" ''
|
|
||||||
The url to use to connect to the ollama server.
|
|
||||||
'';
|
|
||||||
|
|
||||||
|
settingsExample = {
|
||||||
|
model = "mistral";
|
||||||
|
action = "display";
|
||||||
|
url = "http://127.0.0.1:11434";
|
||||||
serve = {
|
serve = {
|
||||||
onStart = helpers.defaultNullOpts.mkBool false ''
|
on_start = false;
|
||||||
Whether to start the ollama server on startup.
|
command = "ollama";
|
||||||
'';
|
args = [ "serve" ];
|
||||||
|
stop_command = "pkill";
|
||||||
command = helpers.defaultNullOpts.mkStr "ollama" ''
|
stop_args = [
|
||||||
The command to use to start the ollama server.
|
|
||||||
'';
|
|
||||||
|
|
||||||
args = helpers.defaultNullOpts.mkListOf types.str [ "serve" ] ''
|
|
||||||
The arguments to pass to the serve command.
|
|
||||||
'';
|
|
||||||
|
|
||||||
stopCommand = helpers.defaultNullOpts.mkStr "pkill" ''
|
|
||||||
The command to use to stop the ollama server.
|
|
||||||
'';
|
|
||||||
|
|
||||||
stopArgs =
|
|
||||||
helpers.defaultNullOpts.mkListOf types.str
|
|
||||||
[
|
|
||||||
"-SIGTERM"
|
"-SIGTERM"
|
||||||
"ollama"
|
"ollama"
|
||||||
]
|
];
|
||||||
''
|
};
|
||||||
The arguments to pass to the stop command.
|
prompts = {
|
||||||
'';
|
my-prompt = {
|
||||||
|
prompt = "Hello $input $sel. J'aime le fromage.";
|
||||||
|
input_label = "> ";
|
||||||
|
action = "display";
|
||||||
|
model = "foo";
|
||||||
|
extract = "```$ftype\n(.-)```";
|
||||||
|
options = {
|
||||||
|
mirostat_eta = 0.1;
|
||||||
|
num_thread = 8;
|
||||||
|
repeat_last_n = -1;
|
||||||
|
stop = "arrêt";
|
||||||
|
};
|
||||||
|
system = "system";
|
||||||
|
format = "json";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
extraPlugins = [ cfg.package ];
|
|
||||||
|
|
||||||
extraConfigLua =
|
|
||||||
let
|
|
||||||
setupOptions =
|
|
||||||
with cfg;
|
|
||||||
{
|
|
||||||
inherit
|
|
||||||
model
|
|
||||||
prompts
|
|
||||||
action
|
|
||||||
url
|
|
||||||
;
|
|
||||||
serve = with serve; {
|
|
||||||
on_start = onStart;
|
|
||||||
inherit command args;
|
|
||||||
stop_command = stopCommand;
|
|
||||||
stop_args = stopArgs;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// cfg.extraOptions;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
require('ollama').setup(${lib.nixvim.toLuaObject setupOptions})
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
plugins/by-name/ollama/deprecations.nix
Normal file
30
plugins/by-name/ollama/deprecations.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
# TODO: introduced 2025-10-06
|
||||||
|
deprecateExtraOptions = true;
|
||||||
|
optionsRenamedToSettings = [
|
||||||
|
"model"
|
||||||
|
"prompts"
|
||||||
|
"action"
|
||||||
|
"url"
|
||||||
|
[
|
||||||
|
"serve"
|
||||||
|
"onStart"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"serve"
|
||||||
|
"command"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"serve"
|
||||||
|
"args"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"serve"
|
||||||
|
"stopCommand"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
"serve"
|
||||||
|
"stopArgs"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -6,14 +6,14 @@
|
||||||
example = {
|
example = {
|
||||||
plugins.ollama = {
|
plugins.ollama = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
settings = {
|
||||||
model = "mistral";
|
model = "mistral";
|
||||||
prompts = {
|
prompts = {
|
||||||
# disable prompt
|
# disable prompt
|
||||||
Sample_Prompt = false;
|
Sample_Prompt = false;
|
||||||
my-prompt = {
|
my-prompt = {
|
||||||
prompt = "Hello $input $sel. J'aime le fromage.";
|
prompt = "Hello $input $sel. J'aime le fromage.";
|
||||||
inputLabel = "> ";
|
input_label = "> ";
|
||||||
action = {
|
action = {
|
||||||
fn = ''
|
fn = ''
|
||||||
function(prompt)
|
function(prompt)
|
||||||
|
|
@ -38,15 +38,16 @@
|
||||||
action = "display";
|
action = "display";
|
||||||
url = "http://127.0.0.1:11434";
|
url = "http://127.0.0.1:11434";
|
||||||
serve = {
|
serve = {
|
||||||
onStart = false;
|
on_start = false;
|
||||||
command = "ollama";
|
command = "ollama";
|
||||||
args = [ "serve" ];
|
args = [ "serve" ];
|
||||||
stopCommand = "pkill";
|
stop_command = "pkill";
|
||||||
stopArgs = [
|
stop_args = [
|
||||||
"-SIGTERM"
|
"-SIGTERM"
|
||||||
"ollama"
|
"ollama"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue