Skip to content

Instantly share code, notes, and snippets.

@shivamsinha15
Forked from rauchg/p.sh
Created January 30, 2024 12:39
Show Gist options
  • Save shivamsinha15/2e6c5d713789161da7d6fff08b8bcaf3 to your computer and use it in GitHub Desktop.
Save shivamsinha15/2e6c5d713789161da7d6fff08b8bcaf3 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'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment