openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.9.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/lib/test_azure.py

66lines · modeblame

08b8179aDavid Schnurr2 years ago1from typing import Union
97a6895bStainless Bot2 years ago2from typing_extensions import Literal
08b8179aDavid Schnurr2 years ago3
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(
13api_version="2023-07-01",
14api_key="example API key",
15azure_endpoint="https://example-resource.azure.openai.com",
16)
17
18async_client = AsyncAzureOpenAI(
19api_version="2023-07-01",
20api_key="example API key",
21azure_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:
27req = client._build_request(
28FinalRequestOptions.construct(
29method="post",
30url="/chat/completions",
31json_data={"model": "my-deployment-model"},
32)
33)
34assert (
35req.url
36== "https://example-resource.azure.openai.com/openai/deployments/my-deployment-model/chat/completions?api-version=2023-07-01"
37)
97a6895bStainless Bot2 years ago38
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:
50if method == "copy":
51copied = client.copy()
52else:
53copied = client.with_options()
54
55assert 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:
63copied = client.copy(
64api_version="2022-05-01",
65)
66assert copied._custom_query == {"api-version": "2022-05-01"}