-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperplexity_api.py
More file actions
21 lines (19 loc) · 831 Bytes
/
perplexity_api.py
File metadata and controls
21 lines (19 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import requests
def analyze_email_with_perplexity(api_key, email_text):
url = "https://api.perplexity.ai/chat/completions"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
email_categories = {"Faktura", "Potwierdzenie zamówienia", "Podróże", "Powiadomienia", "Prywatne", "Inne"}
prompt = (f"Przeanalizuj treść poniższego maila i wybierz jedną z kategorii {email_categories}. Bez uzasadnienia, tylko"
f"jedna kategoria. Treść: {email_text}")
data = {
"model": "sonar",
"messages": [
{"role": "user", "content": prompt}
]
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
return response.json()["choices"][0]["message"]["content"].strip()