Skip to content

Instantly share code, notes, and snippets.

@rauchg
Last active May 18, 2024 13:05
Show Gist options
  • Save rauchg/c5f0b1dc245ad95c593de8336aa382ac to your computer and use it in GitHub Desktop.
Save rauchg/c5f0b1dc245ad95c593de8336aa382ac 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 @- | jq --unbuffered --raw-input -j 'gsub("^data: "; "") | gsub("\r$"; "") | select(. != null and . != "") | fromjson | .choices[0].delta.content'
}
@forthrin
Copy link

Is there a version -- or another tool -- that provides CLI access without registration? (Like running as "Unregistered" in a browser)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment