Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Created March 28, 2023 06:48
Show Gist options
  • Select an option

  • Save benigumocom/4d67aeaaf07b45519b0d812737bbd94a to your computer and use it in GitHub Desktop.

Select an option

Save benigumocom/4d67aeaaf07b45519b0d812737bbd94a to your computer and use it in GitHub Desktop.
OpenAI Chat Completion
#!/bin/sh
while read -r question
do
answer=$(
curl \
-sH POST "https://api.openai.com/v1/chat/completions" \
-H "Content-Type: application/json;charset=utf-8" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d "{
\"model\": \"gpt-3.5-turbo\",
\"messages\": [
{\"role\": \"user\", \"content\": \"$question\"}
]
}" | \
jq -r '.choices[].message.content'
)
echo
echo "$answer"
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment