Skip to content

Instantly share code, notes, and snippets.

@rauchg
Last active October 16, 2024 00:32
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'
}
@TooTallNate
Copy link

@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.

@Gabriel-Alves-Cunha
Copy link

@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 🥺 🙏 ?

@TooTallNate
Copy link

Not sure what you mean. It's up at the top. @rauchg updated the gist already.

@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