openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/lib/test_azure.py
36lines · modecode
| 1 | from typing import Union |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from openai._models import FinalRequestOptions |
| 6 | from openai.lib.azure import AzureOpenAI, AsyncAzureOpenAI |
| 7 | |
| 8 | Client = Union[AzureOpenAI, AsyncAzureOpenAI] |
| 9 | |
| 10 | |
| 11 | sync_client = AzureOpenAI( |
| 12 | api_version="2023-07-01", |
| 13 | api_key="example API key", |
| 14 | azure_endpoint="https://example-resource.azure.openai.com", |
| 15 | ) |
| 16 | |
| 17 | async_client = AsyncAzureOpenAI( |
| 18 | api_version="2023-07-01", |
| 19 | api_key="example API key", |
| 20 | azure_endpoint="https://example-resource.azure.openai.com", |
| 21 | ) |
| 22 | |
| 23 | |
| 24 | @pytest.mark.parametrize("client", [sync_client, async_client]) |
| 25 | def test_implicit_deployment_path(client: Client) -> None: |
| 26 | req = client._build_request( |
| 27 | FinalRequestOptions.construct( |
| 28 | method="post", |
| 29 | url="/chat/completions", |
| 30 | json_data={"model": "my-deployment-model"}, |
| 31 | ) |
| 32 | ) |
| 33 | assert ( |
| 34 | req.url |
| 35 | == "https://example-resource.azure.openai.com/openai/deployments/my-deployment-model/chat/completions?api-version=2023-07-01" |
| 36 | ) |
| 37 | |