Sarah Bentley
commited on
Commit
·
310e177
1
Parent(s):
a2f999a
updating
Browse files- app.py +4 -9
- src/chat.py +4 -34
app.py
CHANGED
|
@@ -60,20 +60,15 @@ def create_chatbot():
|
|
| 60 |
- Return that response as a string
|
| 61 |
"""
|
| 62 |
# TODO: Generate and return response
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
response = chatbot.get_response(message)
|
| 66 |
-
return response
|
| 67 |
-
|
| 68 |
-
except Exception as e:
|
| 69 |
-
return f"I apologize, but I encountered an error. Please try again. Error: {str(e)}"
|
| 70 |
|
| 71 |
|
| 72 |
-
# Create Gradio interface. Customize the interface
|
| 73 |
demo = gr.ChatInterface(
|
| 74 |
chat,
|
| 75 |
title="Boston Public School Selection Assistant",
|
| 76 |
-
description="Ask me anything about Boston public schools! Since I am a free tier chatbot, I may give a 503 error when I'm busy. If that happens, please try again
|
| 77 |
examples=[
|
| 78 |
"I live in Jamaica Plain and want to send my child to kindergarten. What schools are available?"
|
| 79 |
]
|
|
|
|
| 60 |
- Return that response as a string
|
| 61 |
"""
|
| 62 |
# TODO: Generate and return response
|
| 63 |
+
pass
|
| 64 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
+
# Create Gradio interface. Customize the interface however you'd like!
|
| 68 |
demo = gr.ChatInterface(
|
| 69 |
chat,
|
| 70 |
title="Boston Public School Selection Assistant",
|
| 71 |
+
description="Ask me anything about Boston public schools! Since I am a free tier chatbot, I may give a 503 error when I'm busy. If that happens, please try again a few seconds later.",
|
| 72 |
examples=[
|
| 73 |
"I live in Jamaica Plain and want to send my child to kindergarten. What schools are available?"
|
| 74 |
]
|
src/chat.py
CHANGED
|
@@ -37,19 +37,7 @@ class SchoolChatbot:
|
|
| 37 |
User: {user_input}
|
| 38 |
Assistant:"
|
| 39 |
"""
|
| 40 |
-
|
| 41 |
-
You provide accurate information about school programs, locations, enrollment processes, and other important details.
|
| 42 |
-
Always be professional, clear, and focused on helping parents make informed decisions about schools.
|
| 43 |
-
"""
|
| 44 |
-
|
| 45 |
-
# Combine system prompt with user input
|
| 46 |
-
formatted_prompt = f"""
|
| 47 |
-
{system_prompt}
|
| 48 |
-
|
| 49 |
-
User: {user_input}
|
| 50 |
-
Assistant:"""
|
| 51 |
-
|
| 52 |
-
return formatted_prompt
|
| 53 |
|
| 54 |
def get_response(self, user_input):
|
| 55 |
"""
|
|
@@ -67,25 +55,7 @@ class SchoolChatbot:
|
|
| 67 |
str: The chatbot's response
|
| 68 |
|
| 69 |
Implementation tips:
|
| 70 |
-
- Use self.
|
| 71 |
-
- Use self.
|
| 72 |
-
- Consider parameters like temperature and max_length
|
| 73 |
-
- Clean up the response before returning it
|
| 74 |
"""
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
try:
|
| 78 |
-
print("Generating response...")
|
| 79 |
-
response = self.client.text_generation(
|
| 80 |
-
prompt,
|
| 81 |
-
max_new_tokens=300,
|
| 82 |
-
temperature=0.7,
|
| 83 |
-
top_p=0.95,
|
| 84 |
-
do_sample=True,
|
| 85 |
-
return_full_text=False
|
| 86 |
-
)
|
| 87 |
-
return response.strip().split("Assistant:")[-1].strip()
|
| 88 |
-
|
| 89 |
-
except Exception as e:
|
| 90 |
-
print(f"API error: {e}")
|
| 91 |
-
return f"I apologize, but I encountered an error: {str(e)}"
|
|
|
|
| 37 |
User: {user_input}
|
| 38 |
Assistant:"
|
| 39 |
"""
|
| 40 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def get_response(self, user_input):
|
| 43 |
"""
|
|
|
|
| 55 |
str: The chatbot's response
|
| 56 |
|
| 57 |
Implementation tips:
|
| 58 |
+
- Use self.format_prompt() to format the user's input
|
| 59 |
+
- Use self.client to generate responses
|
|
|
|
|
|
|
| 60 |
"""
|
| 61 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|