Created
December 10, 2023 15:33
-
-
Save sergenes/392d8a278d0c46e68551908738214d4a to your computer and use it in GitHub Desktop.
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
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