def from_openai_message_dict(message_dict: Any) -> ChatMessage:
    """Convert openai message dict to generic message."""
    if is_openai_v1():
        # Handling for OpenAI version 1
        role = message_dict.role
        content = message_dict.content
        additional_kwargs = {
            attr: getattr(message_dict, attr)
            for attr in dir(message_dict)
            if not attr.startswith("_") and attr not in ["role", "content"]
        }
    else:
        # Handling for OpenAI version 0
        role = message_dict.get("role")
        content = message_dict.get("content", None)
        additional_kwargs = {
            key: value
            for key, value in message_dict.items()
            if key not in ["role", "content"]
        }

    return ChatMessage(role=role, content=content, additional_kwargs=additional_kwargs)
Convert openai message dict to generic message.
llama-index-integrations/llms/llama-index-llms-konko/llama_index/llms/konko/utils.py