def test_llm_chat(monkeypatch: MonkeyPatch, test_model_id: str) -> None:
    """Test valid chat call to OCI Generative AI LLM service."""
    oci_gen_ai_client = MagicMock()
    llm = OCIGenAI(model=test_model_id, client=oci_gen_ai_client)

    provider = llm._provider.__class__.__name__

    def mocked_response(*args):  # type: ignore[no-untyped-def]
        response_text = "Assistant chat reply."
        response = None
        if provider == "CohereProvider":
            response = MockResponseDict(
                {
                    "status": 200,
                    "data": MockResponseDict(
                        {
                            "chat_response": MockResponseDict(
                                {
                                    "text": response_text,
                                    "finish_reason": "stop",
                                    "documents": [],
                                    "citations": [],
                                    "search_queries": [],
                                    "is_search_required": False,
                                    "tool_calls": None,
                                }
                            ),
                            "model_id": "cohere.command-r-16k",
                            "model_version": "1.0",
                        }
                    ),
                    "request_id": "req-1234567890",
                    "headers": {"content-length": "1234"},
                }
            )
        elif provider == "MetaProvider":
            response = MockResponseDict(
                {
                    "status": 200,
                    "data": MockResponseDict(
                        {
                            "chat_response": MockResponseDict(
                                {
                                    "choices": [
                                        MockResponseDict(
                                            {
                                                "message": MockResponseDict(
                                                    {
                                                        "content": [
                                                            MockResponseDict(
                                                                {
                                                                    "text": response_text,
                                                                }
                                                            )
                                                        ]
                                                    }
                                                ),
                                                "finish_reason": "stop",
                                            }
                                        )
                                    ],
                                    "time_created": "2024-11-03T12:00:00Z",
                                }
                            ),
                            "model_id": "meta.llama-3-70b-instruct",
                            "model_version": "1.0",
                        }
                    ),
                    "request_id": "req-0987654321",
                    "headers": {"content-length": "1234"},
                }
            )
        return response

    monkeypatch.setattr(llm._client, "chat", mocked_response)

    messages = [
        ChatMessage(role="user", content="User message"),
    ]

    # For Meta provider, we expect fewer fields in additional_kwargs
    if provider == "MetaProvider":
        additional_kwargs = {
            "finish_reason": "stop",
            "time_created": "2024-11-03T12:00:00Z",
        }
    else:
        additional_kwargs = {
            "finish_reason": "stop",
            "documents": [],
            "citations": [],
            "search_queries": [],
            "is_search_required": False,
        }

    expected = ChatResponse(
        message=ChatMessage(
            role=MessageRole.ASSISTANT,
            content="Assistant chat reply.",
            additional_kwargs=additional_kwargs,
        ),
        raw={},  # Mocked raw data
        additional_kwargs={
            "model_id": test_model_id,
            "model_version": "1.0",
            "request_id": "req-1234567890"
            if test_model_id == "cohere.command-r-16k"
            else "req-0987654321",
            "content-length": "1234",
        },
    )

    actual = llm.chat(messages, temperature=0.2)
    assert actual.message.content == expected.message.content
Test valid chat call to OCI Generative AI LLM service.
llama-index-integrations/llms/llama-index-llms-oci-genai/tests/test_oci_genai.py