2023-02-22 05:55:23 +00:00
#!/usr/bin/env bash
conversation_file=$(mktemp)
echo new conversation: "$conversation_file"
2023-03-17 00:30:15 +00:00
prompt="You are Mr.Helper. You are an assistant that lives in a floating terminal above my mac. I can summon you with the press of a button! Feel free to use ansii escape codes to add colors or other formatting to your responses."
2023-02-22 05:55:23 +00:00
2023-03-17 00:30:15 +00:00
echo -n "$prompt" | jq -sR '{"role": "system", "content": .}' > "$conversation_file"
2023-02-22 05:55:23 +00:00
2023-03-17 00:30:15 +00:00
while read -rp '> ' prompt ; do
[ -n "$prompt" ] || continue
2023-02-22 05:55:23 +00:00
2023-03-17 00:30:15 +00:00
echo -n "$prompt" | jq -sR '{"role": "user", "content": .}' >> "$conversation_file"
2023-02-22 05:55:23 +00:00
2023-03-17 00:30:15 +00:00
messages=$(jq -rsc < "$conversation_file")
2023-02-22 05:55:23 +00:00
2023-03-17 00:30:15 +00:00
out="$(
http \
-A bearer \
--auth "$(pass openai/api-key)" \
https://api.openai.com/v1/chat/completions \
model=gpt-3.5-turbo \
messages:="$messages"
)"
reply=$(echo "$out" | jq -rc .choices[0].message)
echo "$reply" >> "$conversation_file"
echo "$reply" | jq -rc .content
2023-02-22 05:55:23 +00:00
done