diff options
author | tv <tv@krebsco.de> | 2023-06-14 18:36:13 +0200 |
---|---|---|
committer | tv <tv@krebsco.de> | 2023-06-14 18:36:13 +0200 |
commit | f9e82b4ffc5db0c53556bf068ffc8859828163ef (patch) | |
tree | 6ea55d0492ebb9458fec210c1ec59030e15c3187 /krebs/5pkgs/simple | |
parent | e1ec606542ba602f8ebd95fe961a68aa70c012e4 (diff) | |
parent | ccf29b838bb6865f940597a1bd6e6cb4f3522b0c (diff) |
Merge remote-tracking branch 'orange/master'
Diffstat (limited to 'krebs/5pkgs/simple')
-rw-r--r-- | krebs/5pkgs/simple/vicuna-chat/default.nix | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/vicuna-chat/default.nix b/krebs/5pkgs/simple/vicuna-chat/default.nix new file mode 100644 index 000000000..11a11aabe --- /dev/null +++ b/krebs/5pkgs/simple/vicuna-chat/default.nix @@ -0,0 +1,33 @@ +{ pkgs, ... }: +pkgs.writers.writeDashBin "vicuna-chat" '' + set -efu + + export PATH=${with pkgs; lib.makeBinPath [ + coreutils + curl + jq + ]} + + CONTEXT=''${CONTEXT:-$(date -Id)} + PROMPT=$* + + if ! test -e "$CONTEXT"; then + echo -n 'null' > "$CONTEXT" + fi + + add_to_context() { + jq -rc --argjson message "$1" '. + [$message]' "$CONTEXT" > "$CONTEXT.tmp" + mv "$CONTEXT.tmp" "$CONTEXT" + } + + add_to_context "{\"role\": \"user\", \"content\": \"$PROMPT\"}" + response=$( + jq -nc --slurpfile context "$CONTEXT" '{ + model: "vicuna-13b", + messages: $context[0], + }' | + curl -Ss http://vicuna.r/v1/chat/completions -H 'Content-Type: application/json' -d @- + ) + add_to_context "$(jq -rcn --argjson response "$response" '$response.choices[0].message')" + jq -rcn --argjson response "$response" '$response.choices[0].message.content' +'' |