-
-
Save rauchg/c5f0b1dc245ad95c593de8336aa382ac 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' | |
} |
@nwaughachukwuma We modified it to not use read and instead use a singular jq process to parse the output. This ended up being a lot faster.
@TooTallNate Could you give us the whole script, please 🥺 🙏 ?
Not sure what you mean. It's up at the top. @rauchg updated the gist already.
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
@nwaughachukwuma We modified it to not use
read
and instead use a singularjq
process to parse the output. This ended up being a lot faster.