2023-02-21 21:55:23 -08:00
#!/usr/bin/env bash
conversation_file = $( mktemp)
echo new conversation: " $conversation_file "
2023-03-23 09:11:55 -07:00
OPENAPI_TOKEN = $( pass openai/api-key)
2023-02-21 21:55:23 -08:00
2023-03-16 17:30:15 -07: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-21 21:55:23 -08:00
2023-03-16 17:30:15 -07:00
echo -n " $prompt " | jq -sR '{"role": "system", "content": .}' > " $conversation_file "
2023-02-21 21:55:23 -08:00
2023-03-23 09:12:18 -07:00
bind 'set disable-completion On' 2>/dev/null
2023-03-17 09:45:44 -07:00
printf '\033[48;5;241m\033[38;5;15m'
2023-03-16 17:45:01 -07:00
while read -rep '> ' prompt ; do
2023-03-16 17:30:15 -07:00
[ -n " $prompt " ] || continue
2023-02-21 21:55:23 -08:00
2023-03-16 17:30:15 -07:00
echo -n " $prompt " | jq -sR '{"role": "user", "content": .}' >> " $conversation_file "
2023-02-21 21:55:23 -08:00
2023-03-16 17:30:15 -07:00
messages = $( jq -rsc < " $conversation_file " )
2023-02-21 21:55:23 -08:00
2023-03-16 17:30:15 -07:00
out = " $(
http \
-A bearer \
2023-03-23 09:11:55 -07:00
--auth " $OPENAPI_TOKEN " \
2023-03-16 17:30:15 -07:00
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 "
2023-03-17 09:45:44 -07:00
printf '\033[48;5;235m\033[38;5;15m'
2023-03-16 17:30:15 -07:00
echo " $reply " | jq -rc .content
2023-03-17 09:45:44 -07:00
printf '\033[48;5;241m\033[38;5;15m'
2023-02-21 21:55:23 -08:00
done