lanna_lalala;- commited on
Commit ·
7e2f9b5
1
Parent(s): 92481b6
add api.py
Browse files- phase/Student_view/chatbot.py +1 -1
- utils/api.py +23 -0
- utils/graph.py +0 -0
- utils/seed.py +0 -0
phase/Student_view/chatbot.py
CHANGED
|
@@ -6,7 +6,7 @@ from openai import OpenAI
|
|
| 6 |
# Read from Space Secrets (Settings → Variables & secrets)
|
| 7 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
-
st.error("⚠️ OPENAI_API_KEY is not set. In your Space, add a Secret named OPENAI_API_KEY
|
| 10 |
client = OpenAI(api_key=api_key)
|
| 11 |
|
| 12 |
# --- Helper to add message ---
|
|
|
|
| 6 |
# Read from Space Secrets (Settings → Variables & secrets)
|
| 7 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
+
st.error("⚠️ OPENAI_API_KEY is not set. In your Space, add a Secret named OPENAI_API_KEY ")
|
| 10 |
client = OpenAI(api_key=api_key)
|
| 11 |
|
| 12 |
# --- Helper to add message ---
|
utils/api.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, requests
|
| 2 |
+
|
| 3 |
+
BACKEND = os.getenv("BACKEND_URL").rstrip("/")
|
| 4 |
+
|
| 5 |
+
def start_agent(student_id:int, lesson_id:int, level_slug:str):
|
| 6 |
+
r = requests.post(f"{BACKEND}/agent/start", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug})
|
| 7 |
+
r.raise_for_status()
|
| 8 |
+
return r.json()
|
| 9 |
+
|
| 10 |
+
def get_quiz(student_id:int, lesson_id:int, level_slug:str):
|
| 11 |
+
r = requests.post(f"{BACKEND}/agent/quiz", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug})
|
| 12 |
+
r.raise_for_status()
|
| 13 |
+
return r.json()["items"]
|
| 14 |
+
|
| 15 |
+
def grade_quiz(student_id:int, lesson_id:int, level_slug:str, answers:list[str], assignment_id:int|None=None):
|
| 16 |
+
r = requests.post(f"{BACKEND}/agent/grade", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug,"answers":answers,"assignment_id":assignment_id})
|
| 17 |
+
r.raise_for_status()
|
| 18 |
+
d = r.json(); return d["score"], d["total"]
|
| 19 |
+
|
| 20 |
+
def next_step(student_id:int, lesson_id:int, level_slug:str, answers:list[str], assignment_id:int|None=None):
|
| 21 |
+
r = requests.post(f"{BACKEND}/agent/coach_or_celebrate", json={"student_id":student_id,"lesson_id":lesson_id,"level_slug":level_slug,"answers":answers,"assignment_id":assignment_id})
|
| 22 |
+
r.raise_for_status()
|
| 23 |
+
return r.json()
|
utils/graph.py
DELETED
|
File without changes
|
utils/seed.py
DELETED
|
File without changes
|