Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -758,23 +758,37 @@ with gr.Blocks() as demo:
|
|
| 758 |
)
|
| 759 |
|
| 760 |
def respond(message, history):
|
| 761 |
-
#
|
| 762 |
if history is None:
|
| 763 |
history = []
|
| 764 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
try:
|
| 766 |
-
|
| 767 |
except Exception as e:
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
#
|
| 771 |
-
|
| 772 |
{"role": "user", "content": message},
|
| 773 |
-
{"role": "assistant", "content":
|
| 774 |
]
|
| 775 |
-
|
| 776 |
-
# Clear input
|
| 777 |
-
return "",
|
| 778 |
|
| 779 |
gr.Examples(
|
| 780 |
examples=[
|
|
|
|
| 758 |
)
|
| 759 |
|
| 760 |
def respond(message, history):
|
| 761 |
+
# Initialize history if needed
|
| 762 |
if history is None:
|
| 763 |
history = []
|
| 764 |
+
|
| 765 |
+
# Build smolagents message list
|
| 766 |
+
smol_messages = []
|
| 767 |
+
|
| 768 |
+
# 1. Add system prompt FIRST
|
| 769 |
+
smol_messages.append({"role": "system", "content": system_prompt})
|
| 770 |
+
|
| 771 |
+
# 2. Add full chat history (each entry already {"role", "content"})
|
| 772 |
+
for turn in history:
|
| 773 |
+
smol_messages.append({"role": turn["role"], "content": turn["content"]})
|
| 774 |
+
|
| 775 |
+
# 3. Add the new user message
|
| 776 |
+
smol_messages.append({"role": "user", "content": message})
|
| 777 |
+
|
| 778 |
+
# Run the agent with the FULL conversation
|
| 779 |
try:
|
| 780 |
+
response_text = str(agent.run(smol_messages))
|
| 781 |
except Exception as e:
|
| 782 |
+
response_text = f"[Error] {e}"
|
| 783 |
+
|
| 784 |
+
# Add latest exchange to UI history
|
| 785 |
+
updated_history = history + [
|
| 786 |
{"role": "user", "content": message},
|
| 787 |
+
{"role": "assistant", "content": response_text},
|
| 788 |
]
|
| 789 |
+
|
| 790 |
+
# Clear input + update chat
|
| 791 |
+
return "", updated_history
|
| 792 |
|
| 793 |
gr.Examples(
|
| 794 |
examples=[
|