|
1 | 1 | import json |
2 | 2 | import os |
3 | 3 |
|
4 | | -import httpx |
5 | 4 | from azure.core.credentials import AzureKeyCredential |
6 | 5 | from azure.identity.aio import AzureDeveloperCliCredential, ManagedIdentityCredential, get_bearer_token_provider |
7 | | -from openai import AsyncOpenAI, DefaultAsyncHttpxClient |
| 6 | +from openai import AsyncAzureOpenAI |
8 | 7 | from quart import ( |
9 | 8 | Blueprint, |
10 | 9 | Response, |
@@ -37,21 +36,11 @@ async def configure_openai(): |
37 | 36 | bp.azure_credential, "https://cognitiveservices.azure.com/.default" |
38 | 37 | ) |
39 | 38 |
|
40 | | - class TokenBasedAuth(httpx.Auth): |
41 | | - async def async_auth_flow(self, request): |
42 | | - token = await openai_token_provider() |
43 | | - request.headers["Authorization"] = f"Bearer {token}" |
44 | | - yield request |
45 | | - |
46 | | - def sync_auth_flow(self, request): |
47 | | - raise RuntimeError("Cannot use a sync authentication class with httpx.AsyncClient") |
48 | | - |
49 | 39 | # Create the Asynchronous Azure OpenAI client |
50 | | - bp.openai_client = AsyncOpenAI( |
51 | | - base_url=os.environ["AZURE_INFERENCE_ENDPOINT"], |
52 | | - api_key="placeholder", |
53 | | - default_query={"api-version": "preview"}, |
54 | | - http_client=DefaultAsyncHttpxClient(auth=TokenBasedAuth()), |
| 40 | + bp.openai_client = AsyncAzureOpenAI( |
| 41 | + azure_endpoint=os.environ["AZURE_INFERENCE_ENDPOINT"], |
| 42 | + azure_ad_token_provider=openai_token_provider, |
| 43 | + api_version="2025-04-01-preview", # temporary |
55 | 44 | ) |
56 | 45 |
|
57 | 46 | # Set the model name to the Azure OpenAI model deployment name |
|
0 commit comments