Skip to content

Instantly share code, notes, and snippets.

@sergenes
Created December 10, 2023 15:33
Show Gist options
  • Save sergenes/392d8a278d0c46e68551908738214d4a to your computer and use it in GitHub Desktop.
Save sergenes/392d8a278d0c46e68551908738214d4a to your computer and use it in GitHub Desktop.
import requests
perplexity_api_key = os.getenv('PERPLEXITY_API_KEY_1')
purl = "https://api.perplexity.ai/chat/completions"
pheaders = {
"accept": "application/json",
"authorization": f'Bearer {perplexity_api_key}',
"Content-Type": "application/json"
}
def get_perplexity_completion(prompt, model="llama-2-70b-chat"):
messages = [{"role": "user", "content": prompt}]
data = {
"messages": messages,
"model": model,
"temperature": 0.2
}
perplexity_response = requests.post(purl, headers=pheaders, json=data)
return perplexity_response.json()["choices"][0]["message"]["content"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment