TranscriptProcessor to handle simple and list content
This commit is contained in:
@@ -71,7 +71,9 @@ class TranscriptProcessor(FrameProcessor):
|
|||||||
"""Extract conversation messages from standard format.
|
"""Extract conversation messages from standard format.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
messages: List of messages in standard format with structured content
|
messages: List of messages in OpenAI format, which can be either:
|
||||||
|
- Simple format: {"role": "user", "content": "Hello"}
|
||||||
|
- Content list: {"role": "user", "content": [{"type": "text", "text": "Hello"}]}
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List[TranscriptionMessage]: Normalized conversation messages
|
List[TranscriptionMessage]: Normalized conversation messages
|
||||||
@@ -82,9 +84,17 @@ class TranscriptProcessor(FrameProcessor):
|
|||||||
if msg["role"] not in ("user", "assistant"):
|
if msg["role"] not in ("user", "assistant"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
content = msg.get("content", [])
|
if "content" not in msg:
|
||||||
if isinstance(content, list):
|
logger.warning(f"Message missing content field: {msg}")
|
||||||
# Extract text from structured content
|
continue
|
||||||
|
|
||||||
|
content = msg.get("content")
|
||||||
|
if isinstance(content, str):
|
||||||
|
# Handle simple string content
|
||||||
|
if content:
|
||||||
|
result.append(TranscriptionMessage(role=msg["role"], content=content))
|
||||||
|
elif isinstance(content, list):
|
||||||
|
# Handle structured content
|
||||||
text_parts = []
|
text_parts = []
|
||||||
for part in content:
|
for part in content:
|
||||||
if isinstance(part, dict) and part.get("type") == "text":
|
if isinstance(part, dict) and part.get("type") == "text":
|
||||||
|
|||||||
Reference in New Issue
Block a user