def mock_openai():
    """Set up mock for OpenAI client."""
    # Create mock response
    mock_response = MockEmbeddingResponse()

    # Patch at the module level where the code imports from
    # NVIDIAEmbedding uses: from openai import OpenAI, AsyncOpenAI
    with (
        patch("llama_index.embeddings.nvidia.base.OpenAI") as mock_openai_cls,
        patch(
            "llama_index.embeddings.nvidia.base.AsyncOpenAI"
        ) as mock_async_openai_cls,
    ):
        # Set up the sync client mock
        mock_client = Mock()
        mock_embeddings = Mock()
        mock_embeddings.create.return_value = mock_response
        mock_client.embeddings = mock_embeddings
        mock_openai_cls.return_value = mock_client

        # Set up the async client mock properly
        mock_aclient = Mock()
        mock_aembeddings = Mock()
        # Use AsyncMock for the create method to make it awaitable
        mock_aembeddings.create = AsyncMock(return_value=mock_response)
        mock_aclient.embeddings = mock_aembeddings
        mock_async_openai_cls.return_value = mock_aclient

        yield mock_client, mock_aclient
Set up mock for OpenAI client.
llama-index-integrations/embeddings/llama-index-embeddings-nvidia/tests/test_truncate.py