who needs shell-gpt anyway
This commit is contained in:
parent
a757c003bf
commit
101db8cada
33
ai-chat
33
ai-chat
@ -3,25 +3,26 @@
|
||||
conversation_file=$(mktemp)
|
||||
echo new conversation: "$conversation_file"
|
||||
|
||||
echo '
|
||||
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. If we were in the middle of a conversation, I will tell what has been said so far by including a summary section that begins with {{start summary}} and ends with {{end summary}}. Within that section, every message I have sent you will be prefixed with {{input}} and every message you have send me will be prefixed with {{output}}. Respond to the latest input as if we have just had the exchange that was summarized. Do not prefix your responses with "output".
|
||||
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."
|
||||
|
||||
{{start summary}}
|
||||
' > "$conversation_file"
|
||||
echo -n "$prompt" | jq -sR '{"role": "system", "content": .}' > "$conversation_file"
|
||||
|
||||
while read -rp '> ' in ; do
|
||||
[ -n "$in" ] || continue
|
||||
while read -rp '> ' prompt ; do
|
||||
[ -n "$prompt" ] || continue
|
||||
|
||||
echo '
|
||||
{{input}}' "$in" >> "$conversation_file"
|
||||
echo -n "$prompt" | jq -sR '{"role": "user", "content": .}' >> "$conversation_file"
|
||||
|
||||
conversation="$(< "$conversation_file")
|
||||
{{end summary}}"
|
||||
messages=$(jq -rsc < "$conversation_file")
|
||||
|
||||
echo -n '
|
||||
{{output}}' >> "$conversation_file"
|
||||
|
||||
sgpt --no-animation "$conversation" | tee -a "$conversation_file" | while read -r line; do
|
||||
echo -e "$line"
|
||||
done
|
||||
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
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user