Niansuh commited on
Commit
5b74647
·
verified ·
1 Parent(s): 33934f1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -7
main.py CHANGED
@@ -279,7 +279,7 @@ class Blackbox:
279
  if messages and isinstance(messages[0]['content'], list):
280
  # Prepend prefix to the first text message
281
  for content_part in messages[0]['content']:
282
- if content_part.get('type') == 'text' and not content_part['text'].startswith(prefix):
283
  logger.debug(f"Adding prefix '{prefix}' to the first text message.")
284
  content_part['text'] = f"{prefix} {content_part['text']}"
285
  break
@@ -292,7 +292,7 @@ class Blackbox:
292
  last_message = messages[-1]
293
  if isinstance(last_message['content'], list):
294
  for content_part in last_message['content']:
295
- if content_part.get('type') == 'text':
296
  content_part['role'] = 'user'
297
  else:
298
  last_message['id'] = random_id
@@ -355,7 +355,7 @@ class Blackbox:
355
  logger.error("Image URL not found in the response.")
356
  raise Exception("Image URL not found in the response")
357
  else:
358
- async for chunk in response.content.iter_chunks():
359
  if chunk:
360
  decoded_chunk = chunk.decode(errors='ignore')
361
  decoded_chunk = re.sub(r'\$@\$v=[^$]+\$@\$', '', decoded_chunk)
@@ -452,10 +452,10 @@ async def chat_completions(
452
  # Convert list of content parts to a structured format
453
  combined_content = []
454
  for part in msg.content:
455
- if isinstance(part, TextContent):
456
- combined_content.append({"type": part.type, "text": part.text})
457
- elif isinstance(part, ImageURLContent):
458
- combined_content.append({"type": part.type, "image_url": part.image_url})
459
  processed_messages.append({"role": msg.role, "content": combined_content})
460
  else:
461
  processed_messages.append({"role": msg.role, "content": msg.content})
 
279
  if messages and isinstance(messages[0]['content'], list):
280
  # Prepend prefix to the first text message
281
  for content_part in messages[0]['content']:
282
+ if isinstance(content_part, dict) and content_part.get('type') == 'text' and not content_part['text'].startswith(prefix):
283
  logger.debug(f"Adding prefix '{prefix}' to the first text message.")
284
  content_part['text'] = f"{prefix} {content_part['text']}"
285
  break
 
292
  last_message = messages[-1]
293
  if isinstance(last_message['content'], list):
294
  for content_part in last_message['content']:
295
+ if isinstance(content_part, dict) and content_part.get('type') == 'text':
296
  content_part['role'] = 'user'
297
  else:
298
  last_message['id'] = random_id
 
355
  logger.error("Image URL not found in the response.")
356
  raise Exception("Image URL not found in the response")
357
  else:
358
+ async for chunk, info in response.content.iter_chunks():
359
  if chunk:
360
  decoded_chunk = chunk.decode(errors='ignore')
361
  decoded_chunk = re.sub(r'\$@\$v=[^$]+\$@\$', '', decoded_chunk)
 
452
  # Convert list of content parts to a structured format
453
  combined_content = []
454
  for part in msg.content:
455
+ if isinstance(part, dict) and part.get('type') == 'text':
456
+ combined_content.append({"type": part['type'], "text": part['text']})
457
+ elif isinstance(part, dict) and part.get('type') == 'image_url':
458
+ combined_content.append({"type": part['type'], "image_url": part['image_url']})
459
  processed_messages.append({"role": msg.role, "content": combined_content})
460
  else:
461
  processed_messages.append({"role": msg.role, "content": msg.content})