def test_from_openai_message_dict():
    """Test converting OpenAI message dict back to ChatMessage."""
    # Simple text message
    openai_message = {"role": "user", "content": "Hello, world!"}
    chat_message = from_openai_message_dict(openai_message)
    assert chat_message.role == MessageRole.USER
    assert chat_message.content == "Hello, world!"

    # Message with tool_calls
    tool_calls = [
        {
            "id": "call_123",
            "type": "function",
            "function": {"name": "get_weather", "arguments": '{"location":"NYC"}'},
        }
    ]
    openai_message = {"role": "assistant", "content": None, "tool_calls": tool_calls}
    chat_message = from_openai_message_dict(openai_message)
    assert chat_message.role == MessageRole.ASSISTANT
    assert chat_message.content is None
    assert "tool_calls" in chat_message.additional_kwargs
    assert chat_message.additional_kwargs["tool_calls"] == tool_calls
Test converting OpenAI message dict back to ChatMessage.
llama-index-integrations/llms/llama-index-llms-litellm/tests/test_utils.py