Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -758,37 +758,23 @@ with gr.Blocks() as demo:
|
|
| 758 |
)
|
| 759 |
|
| 760 |
def respond(message, history):
|
| 761 |
-
#
|
| 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 |
-
|
| 781 |
except Exception as e:
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
#
|
| 785 |
-
|
| 786 |
{"role": "user", "content": message},
|
| 787 |
-
{"role": "assistant", "content":
|
| 788 |
]
|
| 789 |
-
|
| 790 |
-
# Clear input
|
| 791 |
-
return "",
|
| 792 |
|
| 793 |
gr.Examples(
|
| 794 |
examples=[
|
|
|
|
| 758 |
)
|
| 759 |
|
| 760 |
def respond(message, history):
|
| 761 |
+
# history here is a list of {"role", "content"} dicts (messages format)
|
| 762 |
if history is None:
|
| 763 |
history = []
|
| 764 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
try:
|
| 766 |
+
out = str(agent.run(message, reset=False))
|
| 767 |
except Exception as e:
|
| 768 |
+
out = f"[Error] {e}"
|
| 769 |
+
|
| 770 |
+
# APPEND MESSAGES AS DICTS, NOT LISTS/TUPLES
|
| 771 |
+
history = history + [
|
| 772 |
{"role": "user", "content": message},
|
| 773 |
+
{"role": "assistant", "content": out},
|
| 774 |
]
|
| 775 |
+
|
| 776 |
+
# Clear input, update chat
|
| 777 |
+
return "", history
|
| 778 |
|
| 779 |
gr.Examples(
|
| 780 |
examples=[
|