Last active
April 2, 2023 20:49
-
-
Save kxzk/69faf0f3c9988efd47e6739af87fe5e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hey_gpt | |
# usage: hey_gpt tell me a joke about a dog | |
set prompt \'(echo $argv | string join ' ')\' | |
set gpt (curl https://api.openai.com/v1/chat/completions -s \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_KEY" \ | |
-d '{ | |
"model": "gpt-4", | |
"messages": [{"role": "user", "content": "'$prompt'"}], | |
"temperature": 0.7, | |
"stream": true | |
}') | |
for text in $gpt | |
if test $text = 'data: [DONE]' | |
break | |
else if string match -q --regex "role" $text | |
continue | |
else if string match -q --regex "content" $text | |
echo -n $text | string replace 'data: ' '' | jq -r -j '.choices[0].delta.content' | |
else | |
continue | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment