def to_openai_message_dicts(
    messages: Sequence[ChatMessage],
    drop_none: bool = False,
    model: Optional[str] = None,
    is_responses_api: bool = False,
) -> Union[List[ChatCompletionMessageParam], str]:
    """Convert generic messages to OpenAI message dicts."""
    if is_responses_api:
        final_message_dicts = []
        final_message_txt = ""
        for message in messages:
            message_dicts = to_openai_responses_message_dict(
                message,
                drop_none=drop_none,
                model="o3-mini",  # hardcode to ensure developer messages are used
            )
            if isinstance(message_dicts, list):
                final_message_dicts.extend(message_dicts)
            elif isinstance(message_dicts, str):
                final_message_txt += message_dicts
            else:
                final_message_dicts.append(message_dicts)
        # this follows the logic of having a string-only input from to_openai_responses_message_dict
        if final_message_txt:
            return final_message_txt
        return final_message_dicts
    else:
        return [
            to_openai_message_dict(
                message,
                drop_none=drop_none,
                model=model,
            )
            for message in messages
        ]
Convert generic messages to OpenAI message dicts.
llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/utils.py