summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/vicuna-chat
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-06-04 21:59:42 +0200
committerlassulus <git@lassul.us>2023-06-04 21:59:42 +0200
commitd453d911ceee894a7c94e015fa982ead0947fa9e (patch)
tree26c0ece76d044541b7b9d2a93adcca286deb90ca /krebs/5pkgs/simple/vicuna-chat
parent68ebb1a9cabf00fbb5f8bd29de9cf6c4e6fd620c (diff)
vicuna-chat: init
Diffstat (limited to 'krebs/5pkgs/simple/vicuna-chat')
-rw-r--r--krebs/5pkgs/simple/vicuna-chat/default.nix33
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'
+''