Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,11 @@ client = OpenAI(api_key=api_key)
|
|
| 10 |
def system_prompt():
|
| 11 |
return "You are a helpful assistant that answers questions about math and physics."
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Chat handler
|
| 14 |
def chat(user_input, history):
|
| 15 |
try:
|
|
@@ -24,6 +29,10 @@ def chat(user_input, history):
|
|
| 24 |
messages=messages
|
| 25 |
)
|
| 26 |
reply = response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
history.append((user_input, reply))
|
| 28 |
return history
|
| 29 |
except Exception as e:
|
|
|
|
| 10 |
def system_prompt():
|
| 11 |
return "You are a helpful assistant that answers questions about math and physics."
|
| 12 |
|
| 13 |
+
# Log unknown questions locally
|
| 14 |
+
def record_unknown_question(question):
|
| 15 |
+
with open("unknown_questions.txt", "a", encoding="utf-8") as f:
|
| 16 |
+
f.write(question + "\n")
|
| 17 |
+
|
| 18 |
# Chat handler
|
| 19 |
def chat(user_input, history):
|
| 20 |
try:
|
|
|
|
| 29 |
messages=messages
|
| 30 |
)
|
| 31 |
reply = response.choices[0].message.content
|
| 32 |
+
# Tool-like behavior: log if unsure
|
| 33 |
+
if "i don't know" in reply.lower() or "i'm not sure" in reply.lower():
|
| 34 |
+
record_unknown_question(user_input)
|
| 35 |
+
|
| 36 |
history.append((user_input, reply))
|
| 37 |
return history
|
| 38 |
except Exception as e:
|