Skip to content

Instantly share code, notes, and snippets.

@BjoernSchilberg
Forked from rauchg/p.sh
Created January 21, 2024 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BjoernSchilberg/a8c104077f737a385ce62fae2f4f0c16 to your computer and use it in GitHub Desktop.
Save BjoernSchilberg/a8c104077f737a385ce62fae2f4f0c16 to your computer and use it in GitHub Desktop.
Perplexity CLI in pure shell
#!/usr/bin/env bash
function p() {
jq -n \
--arg content "$*" \
'{
"model": "pplx-7b-online",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": $content
}
],
"stream": true
}' | curl --silent \
--request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'accept: application/json' \
--header "authorization: Bearer $PERPLEXITY_API" \
--header 'content-type: application/json' \
--data @- |
while read -r line; do
echo "${line:6}" | jq -j '.choices[0].delta.content'
done && echo ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment