-
Notifications
You must be signed in to change notification settings - Fork 0
/
agents.py
45 lines (40 loc) · 1.77 KB
/
agents.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
38
39
40
41
42
43
44
45
import openai
import streamlit as st
# Load API key from Streamlit secrets
openai.api_key = st.secrets["OPENAI_API_KEY"]
def clarification_agent(question):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"A student asked: '{question}'\n\nIs the question clear? If not, ask for more details:"}
]
)
return response.choices[0].message['content'].strip()
def solution_agent(question):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Provide a detailed solution to the following homework question:\n\n{question}\n\nSolution:"}
]
)
return response.choices[0].message['content'].strip()
def quality_assurance_agent(solution):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Review the following solution for accuracy and completeness. Suggest improvements if necessary:\n\n{solution}\n\nReview:"}
]
)
return response.choices[0].message['content'].strip()
def concise_answer_agent(solution):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": f"Provide a concise summary of the following detailed solution:\n\n{solution}\n\nConcise Summary:"}
]
)
return response.choices[0].message['content'].strip()