Didier commited on
Commit
f141d7a
·
verified ·
1 Parent(s): f74574b

Update vlm.py

Browse files
Files changed (1) hide show
  1. vlm.py +13 -2
vlm.py CHANGED
@@ -49,6 +49,14 @@ def encode_image(image_path):
49
  #
50
  # Build messages
51
  #
 
 
 
 
 
 
 
 
52
  def build_messages(message: dict, history: list[dict]):
53
  """Build messages given message & history from a **multimodal** chat interface.
54
  Args:
@@ -77,13 +85,16 @@ def build_messages(message: dict, history: list[dict]):
77
  }
78
  )
79
 
80
- # Append to the history to create the new messages
81
- messages = history
 
 
82
  messages.append({'role': 'user', 'content': user_content})
83
  logger.info(f"{messages=}")
84
 
85
  return messages
86
 
 
87
  #
88
  # stream response
89
  #
 
49
  #
50
  # Build messages
51
  #
52
+ def normalize_message_content(msg: dict) -> dict:
53
+ if isinstance(msg.get("content"), str):
54
+ return {
55
+ "role": msg["role"],
56
+ "content": [{"type": "text", "text": msg["content"]}]
57
+ }
58
+ return msg
59
+
60
  def build_messages(message: dict, history: list[dict]):
61
  """Build messages given message & history from a **multimodal** chat interface.
62
  Args:
 
85
  }
86
  )
87
 
88
+ # Normalize existing history content
89
+ messages = [normalize_message_content(msg) for msg in history]
90
+
91
+ # Append new user message
92
  messages.append({'role': 'user', 'content': user_content})
93
  logger.info(f"{messages=}")
94
 
95
  return messages
96
 
97
+
98
  #
99
  # stream response
100
  #