openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.25.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/lib/test_azure.py

66lines · modecode

1from typing import Union
2from typing_extensions import Literal
3
4import pytest
5
6from openai._models import FinalRequestOptions
7from openai.lib.azure import AzureOpenAI, AsyncAzureOpenAI
8
9Client = Union[AzureOpenAI, AsyncAzureOpenAI]
10
11
12sync_client = AzureOpenAI(
13 api_version="2023-07-01",
14 api_key="example API key",
15 azure_endpoint="https://example-resource.azure.openai.com",
16)
17
18async_client = AsyncAzureOpenAI(
19 api_version="2023-07-01",
20 api_key="example API key",
21 azure_endpoint="https://example-resource.azure.openai.com",
22)
23
24
25@pytest.mark.parametrize("client", [sync_client, async_client])
26def test_implicit_deployment_path(client: Client) -> None:
27 req = client._build_request(
28 FinalRequestOptions.construct(
29 method="post",
30 url="/chat/completions",
31 json_data={"model": "my-deployment-model"},
32 )
33 )
34 assert (
35 req.url
36 == "https://example-resource.azure.openai.com/openai/deployments/my-deployment-model/chat/completions?api-version=2023-07-01"
37 )
38
39
40@pytest.mark.parametrize(
41 "client,method",
42 [
43 (sync_client, "copy"),
44 (sync_client, "with_options"),
45 (async_client, "copy"),
46 (async_client, "with_options"),
47 ],
48)
49def test_client_copying(client: Client, method: Literal["copy", "with_options"]) -> None:
50 if method == "copy":
51 copied = client.copy()
52 else:
53 copied = client.with_options()
54
55 assert copied._custom_query == {"api-version": "2023-07-01"}
56
57
58@pytest.mark.parametrize(
59 "client",
60 [sync_client, async_client],
61)
62def test_client_copying_override_options(client: Client) -> None:
63 copied = client.copy(
64 api_version="2022-05-01",
65 )
66 assert copied._custom_query == {"api-version": "2022-05-01"}
67