-
-
Save shivamsinha15/2e6c5d713789161da7d6fff08b8bcaf3 to your computer and use it in GitHub Desktop.
Perplexity CLI in pure shell
This file contains 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 characters
#!/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