Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: considering default_headers for realtime headers #1976

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/openai/_utils/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def blocking_func(arg1, arg2, kwarg1=None):
# blocking code
return result


result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
```

Expand Down
4 changes: 2 additions & 2 deletions src/openai/resources/beta/realtime/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def connect(
return RealtimeConnectionManager(
client=self._client,
extra_query=extra_query,
extra_headers=extra_headers,
extra_headers=extra_headers or self._client.default_headers,
websocket_connection_options=websocket_connection_options,
model=model,
)
Expand Down Expand Up @@ -148,7 +148,7 @@ def connect(
return AsyncRealtimeConnectionManager(
client=self._client,
extra_query=extra_query,
extra_headers=extra_headers,
extra_headers=extra_headers or self._client.default_headers,
websocket_connection_options=websocket_connection_options,
model=model,
)
Expand Down
24 changes: 7 additions & 17 deletions tests/lib/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def token_provider() -> str:


class TestAzureLogging:

@pytest.fixture(autouse=True)
def logger_with_filter(self) -> logging.Logger:
logger = logging.getLogger("openai")
Expand All @@ -165,9 +164,7 @@ def logger_with_filter(self) -> logging.Logger:
def test_azure_api_key_redacted(self, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture) -> None:
respx_mock.post(
"https://example-resource.azure.openai.com/openai/deployments/gpt-4/chat/completions?api-version=2024-06-01"
).mock(
return_value=httpx.Response(200, json={"model": "gpt-4"})
)
).mock(return_value=httpx.Response(200, json={"model": "gpt-4"}))

client = AzureOpenAI(
api_version="2024-06-01",
Expand All @@ -182,14 +179,11 @@ def test_azure_api_key_redacted(self, respx_mock: MockRouter, caplog: pytest.Log
if is_dict(record.args) and record.args.get("headers") and is_dict(record.args["headers"]):
assert record.args["headers"]["api-key"] == "<redacted>"


@pytest.mark.respx()
def test_azure_bearer_token_redacted(self, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture) -> None:
respx_mock.post(
"https://example-resource.azure.openai.com/openai/deployments/gpt-4/chat/completions?api-version=2024-06-01"
).mock(
return_value=httpx.Response(200, json={"model": "gpt-4"})
)
).mock(return_value=httpx.Response(200, json={"model": "gpt-4"}))

client = AzureOpenAI(
api_version="2024-06-01",
Expand All @@ -204,15 +198,12 @@ def test_azure_bearer_token_redacted(self, respx_mock: MockRouter, caplog: pytes
if is_dict(record.args) and record.args.get("headers") and is_dict(record.args["headers"]):
assert record.args["headers"]["Authorization"] == "<redacted>"


@pytest.mark.asyncio
@pytest.mark.respx()
async def test_azure_api_key_redacted_async(self, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture) -> None:
respx_mock.post(
"https://example-resource.azure.openai.com/openai/deployments/gpt-4/chat/completions?api-version=2024-06-01"
).mock(
return_value=httpx.Response(200, json={"model": "gpt-4"})
)
).mock(return_value=httpx.Response(200, json={"model": "gpt-4"}))

client = AsyncAzureOpenAI(
api_version="2024-06-01",
Expand All @@ -227,15 +218,14 @@ async def test_azure_api_key_redacted_async(self, respx_mock: MockRouter, caplog
if is_dict(record.args) and record.args.get("headers") and is_dict(record.args["headers"]):
assert record.args["headers"]["api-key"] == "<redacted>"


@pytest.mark.asyncio
@pytest.mark.respx()
async def test_azure_bearer_token_redacted_async(self, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture) -> None:
async def test_azure_bearer_token_redacted_async(
self, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture
) -> None:
respx_mock.post(
"https://example-resource.azure.openai.com/openai/deployments/gpt-4/chat/completions?api-version=2024-06-01"
).mock(
return_value=httpx.Response(200, json={"model": "gpt-4"})
)
).mock(return_value=httpx.Response(200, json={"model": "gpt-4"}))

client = AsyncAzureOpenAI(
api_version="2024-06-01",
Expand Down