simonguest commited on
Commit
6c5b6cf
·
1 Parent(s): a349175

Changed page title and added error handling

Browse files
Files changed (2) hide show
  1. app.py +13 -7
  2. tutor.py +0 -1
app.py CHANGED
@@ -8,15 +8,21 @@ from tutor import Tutor
8
 
9
 
10
  def submit_chat(tutor_ctx, message):
11
- tutor = Tutor(context=tutor_ctx)
12
- for history in tutor.chat(message):
13
- yield [tutor.serialize(), history, None]
 
 
 
14
 
15
 
16
  def submit_code(tutor_ctx, editor, output):
17
- tutor = Tutor(context=tutor_ctx)
18
- for history in tutor.code(editor, output):
19
- yield [tutor.serialize(), history, None]
 
 
 
20
 
21
 
22
  def init_tutor(instructions, starter_code):
@@ -51,7 +57,7 @@ def load_level(request: gr.Request):
51
  return [instructions, starter_code]
52
 
53
 
54
- with gr.Blocks() as demo:
55
  tutor_ctx = gr.State()
56
  with gr.Row():
57
  instruction_panel = gr.Markdown()
 
8
 
9
 
10
  def submit_chat(tutor_ctx, message):
11
+ try:
12
+ tutor = Tutor(context=tutor_ctx)
13
+ for history in tutor.chat(message):
14
+ yield [tutor.serialize(), history, None]
15
+ except Exception as error:
16
+ raise gr.Error(str(error))
17
 
18
 
19
  def submit_code(tutor_ctx, editor, output):
20
+ try:
21
+ tutor = Tutor(context=tutor_ctx)
22
+ for history in tutor.code(editor, output):
23
+ yield [tutor.serialize(), history, None]
24
+ except Exception as error:
25
+ raise gr.Error(str(error))
26
 
27
 
28
  def init_tutor(instructions, starter_code):
 
57
  return [instructions, starter_code]
58
 
59
 
60
+ with gr.Blocks(title="CS Tutor") as demo:
61
  tutor_ctx = gr.State()
62
  with gr.Row():
63
  instruction_panel = gr.Markdown()
tutor.py CHANGED
@@ -18,7 +18,6 @@ class Tutor:
18
  self.deserialize(context)
19
  else:
20
  self.memory = []
21
- # self.system_prompt = system_prompt(instructions, starter_code)
22
  self.instructions = instructions
23
  self.starter_code = starter_code
24
  self.memory.append(
 
18
  self.deserialize(context)
19
  else:
20
  self.memory = []
 
21
  self.instructions = instructions
22
  self.starter_code = starter_code
23
  self.memory.append(