sdufays commited on
Commit
4a6edcf
·
1 Parent(s): 5003d54

Implementing SchoolChatbot logic

Browse files
Files changed (2) hide show
  1. app.py +0 -1
  2. src/chat.py +26 -2
app.py CHANGED
@@ -18,7 +18,6 @@ Example Usage:
18
  # http://localhost:7860
19
  """
20
 
21
- # edit to create repo
22
  import gradio as gr
23
  from src.chat import SchoolChatbot
24
 
 
18
  # http://localhost:7860
19
  """
20
 
 
21
  import gradio as gr
22
  from src.chat import SchoolChatbot
23
 
src/chat.py CHANGED
@@ -37,7 +37,13 @@ class SchoolChatbot:
37
  User: {user_input}
38
  Assistant:"
39
  """
40
- pass
 
 
 
 
 
 
41
 
42
  def get_response(self, user_input):
43
  """
@@ -58,4 +64,22 @@ class SchoolChatbot:
58
  - Use self.format_prompt() to format the user's input
59
  - Use self.client to generate responses
60
  """
61
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  User: {user_input}
38
  Assistant:"
39
  """
40
+ return (
41
+ "You are a helpful assistant that specializes in helping parents choose Boston Public Schools"
42
+ "Answer clearly and accurately using the latest school registration rules, deadlines, and program information."
43
+ "Always be professional, clear, and focused on helping parents make informed decisions about schools.\n\n"
44
+ f"User: {user_input}\n"
45
+ "Assistant:"
46
+ )
47
 
48
  def get_response(self, user_input):
49
  """
 
64
  - Use self.format_prompt() to format the user's input
65
  - Use self.client to generate responses
66
  """
67
+ prompt = self.format_prompt(user_input)
68
+
69
+ try:
70
+ print("Generating response...")
71
+ # TODO: revisit parameters later for formatting or prompt optimization.
72
+ response = self.client.text_generation(
73
+ prompt,
74
+ max_new_tokens=512,
75
+ stop=["User:", "Assistant:"],
76
+ do_sample=False, # better to have a deterministic decoding
77
+ return_full_text=False
78
+ )
79
+ return response.strip()
80
+
81
+ except Exception as e:
82
+ print(f"API error: {e}")
83
+ return f"I apologize, but I encountered an error: {str(e)}"
84
+
85
+