nix/home/program/bash/module/Ask.nix

29 lines
708 B
Nix
Raw Normal View History

2024-10-23 19:21:14 +03:00
{ ... }:
{
text = ''
# Ask general AI.
# Usage: ask <QUERY>
function ask() {
curl http://localhost:11434/api/generate -d "{
2024-10-23 20:29:27 +03:00
\"model\":\"''${OLLAMA_MODEL}\",
\"raw\":true,
2024-10-23 19:21:14 +03:00
\"prompt\":\"''${*}\"
2024-10-23 20:29:27 +03:00
}" 2> /dev/null | parallel -j1 -- "printf '%s\n' {} | jq -r .response | sed -e 's/^$/\+\+\+/' | tr -d '\n' | sed -e 's/\+\+\+/\n/'"
2024-10-23 19:21:14 +03:00
echo
}
# Specify ask model.
function ask_model() {
export OLLAMA_MODEL="''${1}"
}
function _complete_ask_model() {
local IFS=$'\n'
local models=($(ollama list | sed -e "1d" | cut -f1))
_autocomplete_first ''${models[@]}
}
complete -F _complete_ask_model ask_model
'';
}