Krika commited on
Commit
f3c1dfa
·
1 Parent(s): 91d48f5

init frontend sherika

Browse files
phase/Student_view/practice_quiz.py ADDED
@@ -0,0 +1 @@
 
 
1
+ #added a practice_quiz.py (for the general practice quiz code could go here and the lesson_quiz code stuff in quiz.py)
utils/api.py CHANGED
@@ -1,6 +1,7 @@
1
  # utils/api.py
2
  import os, requests
3
 
 
4
  BACKEND = (os.getenv("BACKEND_URL") or "").strip().rstrip("/")
5
  if not BACKEND:
6
  raise RuntimeError("BACKEND_URL is not set in Space secrets.")
@@ -12,18 +13,17 @@ _session = requests.Session()
12
  if TOKEN:
13
  _session.headers["Authorization"] = f"Bearer {TOKEN}"
14
 
 
15
  def _req(method: str, path: str, **kw):
16
  # make sure path starts with '/'
17
  if not path.startswith("/"):
18
  path = "/" + path
19
  url = f"{BACKEND}{path}"
20
- # apply a default timeout unless the caller overrides it
21
  kw.setdefault("timeout", DEFAULT_TIMEOUT)
22
  try:
23
  r = _session.request(method, url, **kw)
24
  r.raise_for_status()
25
  except requests.HTTPError as e:
26
- # Surface readable API errors in the UI
27
  body = ""
28
  try:
29
  body = r.text[:500]
@@ -31,13 +31,16 @@ def _req(method: str, path: str, **kw):
31
  pass
32
  raise RuntimeError(f"{method} {path} failed [{r.status_code}]: {body}") from e
33
  except requests.RequestException as e:
34
- # Network/DNS/timeouts, etc.
35
  raise RuntimeError(f"{method} {path} failed: {e.__class__.__name__}: {e}") from e
36
  return r
37
 
 
 
38
  def health():
39
  return _req("GET", "/health").json()
40
 
 
 
41
  def start_agent(student_id: int, lesson_id: int, level_slug: str):
42
  return _req("POST", "/agent/start",
43
  json={"student_id": student_id, "lesson_id": lesson_id, "level_slug": level_slug}).json()
@@ -59,6 +62,8 @@ def next_step(student_id: int, lesson_id: int, level_slug: str,
59
  json={"student_id": student_id, "lesson_id": lesson_id, "level_slug": level_slug,
60
  "answers": answers, "assignment_id": assignment_id}).json()
61
 
 
 
62
  def login(email: str, password: str):
63
  return _req("POST", "/auth/login", json={"email": email, "password": password}).json()
64
 
@@ -67,7 +72,25 @@ def signup_student(name: str, email: str, password: str, level_label: str, count
67
  json={"name": name, "email": email, "password": password,
68
  "level_label": level_label, "country_label": country_label}).json()
69
 
70
- # Optional: if your frontend has a teacher sign-up flow
71
  def signup_teacher(title: str, name: str, email: str, password: str):
72
  return _req("POST", "/auth/signup/teacher",
73
  json={"title": title, "name": name, "email": email, "password": password}).json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # utils/api.py
2
  import os, requests
3
 
4
+ # ---- Setup ----
5
  BACKEND = (os.getenv("BACKEND_URL") or "").strip().rstrip("/")
6
  if not BACKEND:
7
  raise RuntimeError("BACKEND_URL is not set in Space secrets.")
 
13
  if TOKEN:
14
  _session.headers["Authorization"] = f"Bearer {TOKEN}"
15
 
16
+
17
  def _req(method: str, path: str, **kw):
18
  # make sure path starts with '/'
19
  if not path.startswith("/"):
20
  path = "/" + path
21
  url = f"{BACKEND}{path}"
 
22
  kw.setdefault("timeout", DEFAULT_TIMEOUT)
23
  try:
24
  r = _session.request(method, url, **kw)
25
  r.raise_for_status()
26
  except requests.HTTPError as e:
 
27
  body = ""
28
  try:
29
  body = r.text[:500]
 
31
  pass
32
  raise RuntimeError(f"{method} {path} failed [{r.status_code}]: {body}") from e
33
  except requests.RequestException as e:
 
34
  raise RuntimeError(f"{method} {path} failed: {e.__class__.__name__}: {e}") from e
35
  return r
36
 
37
+
38
+ # ---- Health ----
39
  def health():
40
  return _req("GET", "/health").json()
41
 
42
+
43
+ # ---- Legacy agent endpoints (keep) ----
44
  def start_agent(student_id: int, lesson_id: int, level_slug: str):
45
  return _req("POST", "/agent/start",
46
  json={"student_id": student_id, "lesson_id": lesson_id, "level_slug": level_slug}).json()
 
62
  json={"student_id": student_id, "lesson_id": lesson_id, "level_slug": level_slug,
63
  "answers": answers, "assignment_id": assignment_id}).json()
64
 
65
+
66
+ # ---- Auth ----
67
  def login(email: str, password: str):
68
  return _req("POST", "/auth/login", json={"email": email, "password": password}).json()
69
 
 
72
  json={"name": name, "email": email, "password": password,
73
  "level_label": level_label, "country_label": country_label}).json()
74
 
 
75
  def signup_teacher(title: str, name: str, email: str, password: str):
76
  return _req("POST", "/auth/signup/teacher",
77
  json={"title": title, "name": name, "email": email, "password": password}).json()
78
+
79
+
80
+ # ---- New LangGraph-backed endpoints ----
81
+ def fetch_lesson_content(lesson: str, module: str, topic: str):
82
+ payload = {"lesson": lesson, "module": module, "topic": topic}
83
+ r = _req("POST", "/lesson", json=payload).json()
84
+ return r["lesson_content"]
85
+
86
+ def submit_lesson_quiz(lesson: str, module: str, topic: str, responses: dict):
87
+ payload = {"lesson": lesson, "module": module, "topic": topic, "responses": responses}
88
+ return _req("POST", "/lesson-quiz", json=payload).json()
89
+
90
+ def submit_practice_quiz(lesson: str, responses: dict):
91
+ payload = {"lesson": lesson, "responses": responses}
92
+ return _req("POST", "/practice-quiz", json=payload).json()
93
+
94
+ def send_to_chatbot(messages: list[dict]):
95
+ payload = {"messages": messages}
96
+ return _req("POST", "/chatbot", json=payload).json()