Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perplexity CLI in pure shell #946

Open
1 task
ShellLM opened this issue Nov 13, 2024 · 1 comment
Open
1 task

Perplexity CLI in pure shell #946

ShellLM opened this issue Nov 13, 2024 · 1 comment
Labels
AI-Chatbots Topics related to advanced chatbot platforms integrating multiple AI models ai-platform model hosts and APIs CLI-UX Command Line Interface user experience and best practices Git-Repo Source code repository like gitlab or gh github gh tools like cli, Actions, Issues, Pages shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets

Comments

@ShellLM
Copy link
Collaborator

ShellLM commented Nov 13, 2024

Perplexity CLI in pure shell

p.sh

#!/usr/bin/env bash
function p() {
    local json_request
    json_request=$(jq -n \
        --arg content "$*" \
        '{
          "model": "pplx-7b-online",
          "messages": [
            {"role": "system", "content": "Be precise and concise."},
            {"role": "user", "content": $content}
          ],
          "stream": false
        }')

    local json_response
    json_response=$(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 "$json_request")

    echo "$json_response" | jq --raw-output .choices[0].message.content
}

p "$*"

Usage

To use this script, you'll need to have the jq command-line JSON processor installed, and the PERPLEXITY_API environment variable set to your Perplexity API key.

Then you can simply run the script and pass your prompt as an argument:

$ PERPLEXITY_API=YOUR_API_KEY ./p.sh "What is the square root of 64?"
8

Related Discussion

Suggested Labels

  • shell
  • cli
  • perplexity
  • api

Suggested labels

None

@ShellLM ShellLM added AI-Chatbots Topics related to advanced chatbot platforms integrating multiple AI models ai-platform model hosts and APIs CLI-UX Command Line Interface user experience and best practices Git-Repo Source code repository like gitlab or gh github gh tools like cli, Actions, Issues, Pages shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets labels Nov 13, 2024
@ShellLM
Copy link
Collaborator Author

ShellLM commented Nov 13, 2024

Related content

#924 similarity score: 0.89
#743 similarity score: 0.88
#309 similarity score: 0.86
#713 similarity score: 0.86
#114 similarity score: 0.86
#62 similarity score: 0.86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI-Chatbots Topics related to advanced chatbot platforms integrating multiple AI models ai-platform model hosts and APIs CLI-UX Command Line Interface user experience and best practices Git-Repo Source code repository like gitlab or gh github gh tools like cli, Actions, Issues, Pages shell-script shell scripting in Bash, ZSH, POSIX etc source-code Code snippets
Projects
None yet
Development

No branches or pull requests

1 participant