-
Notifications
You must be signed in to change notification settings - Fork 1
/
perplexityAI_Integration.py
37 lines (31 loc) · 1.14 KB
/
perplexityAI_Integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from openai import OpenAI
def perplexityAI(majorName):
open('courseSchedule.txt', 'w').close()
with open('.env', 'r') as file:
API_KEY = file.readline()
model = 'pplx-7b-online'
prompt = f'Give me a 4 year plan semester by semester for a {majorName} major at the University Of Virginia based on the University Of Virginia requirements. Please dont repeat class suggestions,' \
f'and please give specific classes.'
messages = [
{
"role": "system",
"content": (
"You are a helpful assistant who provides course plans and guidance for users at the University Of Virginia."
),
},
{
"role": "user",
"content": (
prompt
),
},
]
client = OpenAI(api_key=API_KEY, base_url="https://api.perplexity.ai")
response = client.chat.completions.create(
model=model,
messages=messages,
max_tokens=4000
)
with open("courseSchedule.txt", mode="wt") as file:
file.write(response.choices[0].message.content)
# print(response.choices[0].message.content)