Created
April 9, 2023 07:19
-
-
Save woodongwong/7d186f164982ce483198bd384a005d72 to your computer and use it in GitHub Desktop.
Revisions
-
woodongwong renamed this gist
Apr 9, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
woodongwong created this gist
Apr 9, 2023 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/usr/bin/env sh OPENAI_API_KEY="sk-xxx" request_params=$( cat <<EOF { "model": "gpt-3.5-turbo", "stream": true, "messages": [ { "role": "user", "content": "$1" } ] } EOF ) curl --header "Authorization: Bearer $OPENAI_API_KEY" \ --header 'Content-Type: application/json' \ --data "$request_params" -N -s 'https://api.openai.com/v1/chat/completions' | awk -F 'data: ' '{print $2; system("")}' | jq --unbuffered -R 'fromjson?' | jq --unbuffered -r '(.choices[].delta.content)? | select(. != null)' | awk '{printf "%s", $0}' echo