async def test_structured_chat_simple_async(MockAsyncOpenAI: MagicMock):
    """Simple async test for structured output using as_structured_llm."""
    from pydantic import BaseModel, Field
    from llama_index.core.base.llms.types import ChatMessage

    class Person(BaseModel):
        name: str = Field(description="The person's name")
        age: int = Field(description="The person's age")

    # Mock OpenAI response structure
    mock_choice = MagicMock()
    mock_choice.message.role = "assistant"
    mock_choice.message.content = '{"name": "Bob", "age": 30}'

    mock_response = MagicMock()
    mock_response.choices = [mock_choice]

    # Mock async OpenAI client
    mock_client = MagicMock()
    create_fn = AsyncMock()
    create_fn.return_value = mock_response
    mock_client.chat.completions.create = create_fn
    MockAsyncOpenAI.return_value = mock_client

    # Instantiate OpenAI class
    llm = OpenAI(model="gpt-4o", api_key="test-key")
    structured_llm = llm.as_structured_llm(Person)
    messages = [ChatMessage(role="user", content="Create a person named Bob who is 30")]
    result = await structured_llm.achat(messages)

    # Verify the result has the expected structure
    assert isinstance(result.raw, Person)
Simple async test for structured output using as_structured_llm.
llama-index-integrations/llms/llama-index-llms-openai/tests/test_openai.py