File size: 748 Bytes
3cfb95f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from logging_config import setup_logger


logger = setup_logger(__name__)



def extract_text_from_content(content):
    """Extract text from various message content formats."""
    if isinstance(content, str):
        return content
    elif isinstance(content, list):
        # Handle list of text items or dictionaries
        text_parts = []
        for item in content:
            if isinstance(item, dict):
                # Extract text from dictionary format
                if 'text' in item:
                    text_parts.append(item['text'])
            elif isinstance(item, str):
                text_parts.append(item)
        return ''.join(text_parts)
    else:
        # Fallback for any other format
        return str(content)