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)
|
conversation_file=$(mktemp)
|
||||||
echo new conversation: "$conversation_file"
|
echo new conversation: "$conversation_file"
|
||||||
|
|
||||||
echo '
|
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."
|
||||||
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".
|
|
||||||
|
|
||||||
{{start summary}}
|
echo -n "$prompt" | jq -sR '{"role": "system", "content": .}' > "$conversation_file"
|
||||||
' > "$conversation_file"
|
|
||||||
|
|
||||||
while read -rp '> ' in ; do
|
while read -rp '> ' prompt ; do
|
||||||
[ -n "$in" ] || continue
|
[ -n "$prompt" ] || continue
|
||||||
|
|
||||||
echo '
|
echo -n "$prompt" | jq -sR '{"role": "user", "content": .}' >> "$conversation_file"
|
||||||
{{input}}' "$in" >> "$conversation_file"
|
|
||||||
|
|
||||||
conversation="$(< "$conversation_file")
|
messages=$(jq -rsc < "$conversation_file")
|
||||||
{{end summary}}"
|
|
||||||
|
|
||||||
echo -n '
|
out="$(
|
||||||
{{output}}' >> "$conversation_file"
|
http \
|
||||||
|
-A bearer \
|
||||||
sgpt --no-animation "$conversation" | tee -a "$conversation_file" | while read -r line; do
|
--auth "$(pass openai/api-key)" \
|
||||||
echo -e "$line"
|
https://api.openai.com/v1/chat/completions \
|
||||||
done
|
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
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user