CORVO-AI commited on
Commit
8d5313c
·
verified ·
1 Parent(s): 33a2564

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -23
app.py CHANGED
@@ -196,42 +196,23 @@ def chat_with_assistant(user_input, chat_history, bot_id, workspace_id, temperat
196
  # Process chat history into the format expected by the API
197
  messages = []
198
  system_prompt = ""
 
199
  for msg in chat_history:
200
  if msg["role"] == "system":
201
  system_prompt = msg["content"]
202
  elif msg["role"] in ["user", "assistant"]:
203
- # Handle multipart messages (for images)
204
  if "type" in msg and msg["type"] == "multipart" and "content" in msg:
205
- content_array = []
206
- for part in msg["content"]:
207
- if part["type"] == "text":
208
- content_array.append({
209
- "type": "text",
210
- "text": part["text"]
211
- })
212
- elif part["type"] == "image":
213
- content_array.append({
214
- "type": "image_url",
215
- "image_url": {
216
- "url": part["url"]
217
- }
218
- })
219
- messages.append({
220
- "role": msg["role"],
221
- "content": content_array
222
- })
223
  # Handle regular text messages
224
  else:
225
- # For text messages, content must be a string without a type field
226
  messages.append({
227
  "role": msg["role"],
228
  "content": msg["content"]
229
  })
230
 
231
  # Add the latest user input if not already in chat history
232
- # Only add if it's a simple text input (not multipart)
233
- if user_input and isinstance(user_input, str) and (not messages or messages[-1]["role"] != "user" or
234
- (isinstance(messages[-1]["content"], str) and messages[-1]["content"] != user_input)):
235
  messages.append({
236
  "role": "user",
237
  "content": user_input
 
196
  # Process chat history into the format expected by the API
197
  messages = []
198
  system_prompt = ""
199
+
200
  for msg in chat_history:
201
  if msg["role"] == "system":
202
  system_prompt = msg["content"]
203
  elif msg["role"] in ["user", "assistant"]:
204
+ # Pass multipart messages directly without modifying their structure
205
  if "type" in msg and msg["type"] == "multipart" and "content" in msg:
206
+ messages.append(msg) # Keep the original multipart structure
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  # Handle regular text messages
208
  else:
 
209
  messages.append({
210
  "role": msg["role"],
211
  "content": msg["content"]
212
  })
213
 
214
  # Add the latest user input if not already in chat history
215
+ if user_input and isinstance(user_input, str) and (not messages or messages[-1]["role"] != "user" or messages[-1]["content"] != user_input):
 
 
216
  messages.append({
217
  "role": "user",
218
  "content": user_input