Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ class ChatMessage:
|
|
13 |
role: str
|
14 |
content: str
|
15 |
|
16 |
-
def
|
17 |
"""Converts ChatMessage to a dictionary for JSON serialization."""
|
18 |
return {"role": self.role, "content": self.content}
|
19 |
|
@@ -162,10 +162,7 @@ class XylariaChat:
|
|
162 |
|
163 |
# Convert existing conversation history to ChatMessage objects and then to dictionaries
|
164 |
for msg in self.conversation_history:
|
165 |
-
messages.append(
|
166 |
-
role=msg['role'],
|
167 |
-
content=msg['content']
|
168 |
-
).to_dict())
|
169 |
|
170 |
# Process image if uploaded
|
171 |
if image:
|
@@ -270,12 +267,8 @@ class XylariaChat:
|
|
270 |
return
|
271 |
|
272 |
# Update conversation history
|
273 |
-
self.conversation_history.append(
|
274 |
-
|
275 |
-
)
|
276 |
-
self.conversation_history.append(
|
277 |
-
{"role": "assistant", "content": full_response}
|
278 |
-
)
|
279 |
|
280 |
# Limit conversation history
|
281 |
if len(self.conversation_history) > 10:
|
|
|
13 |
role: str
|
14 |
content: str
|
15 |
|
16 |
+
def to_dict(self):
|
17 |
"""Converts ChatMessage to a dictionary for JSON serialization."""
|
18 |
return {"role": self.role, "content": self.content}
|
19 |
|
|
|
162 |
|
163 |
# Convert existing conversation history to ChatMessage objects and then to dictionaries
|
164 |
for msg in self.conversation_history:
|
165 |
+
messages.append(msg)
|
|
|
|
|
|
|
166 |
|
167 |
# Process image if uploaded
|
168 |
if image:
|
|
|
267 |
return
|
268 |
|
269 |
# Update conversation history
|
270 |
+
self.conversation_history.append(ChatMessage(role="user", content=message).to_dict())
|
271 |
+
self.conversation_history.append(ChatMessage(role="assistant", content=full_response).to_dict())
|
|
|
|
|
|
|
|
|
272 |
|
273 |
# Limit conversation history
|
274 |
if len(self.conversation_history) > 10:
|