Skip to content
Draft
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
7 changes: 3 additions & 4 deletions src/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ async def lifespan(app: fastapi.FastAPI):
default_credential = azure.identity.aio.DefaultAzureCredential(
exclude_shared_token_cache_credential=True
)
client_args["azure_ad_token_provider"] = azure.identity.aio.get_bearer_token_provider(
client_args["api_key"] = azure.identity.aio.get_bearer_token_provider(
default_credential, "https://cognitiveservices.azure.com/.default"
)
clients["openai"] = openai.AsyncAzureOpenAI(
api_version="2023-07-01-preview",
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
clients["openai"] = openai.AsyncOpenAI(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to have "/openai/v1" at end of the URL

base_url=os.getenv("AZURE_OPENAI_ENDPOINT"),
**client_args,
)

Expand Down
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fastapi==0.111.0
uvicorn[standard]==0.30.1
gunicorn==22.0.0
openai>=1.47.0
openai>=1.108.1
azure-identity==1.16.1
python-dotenv # Pinned due to docker-in-docker issue: https://github.com/devcontainers/features/issues/616
environs==11.0.0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def test_openai_azure_defaultcredential(monkeypatch, mock_azure_credential
fastapi_app = api.create_app()

with TestClient(fastapi_app):
assert api.globals.clients["openai"]._azure_ad_token_provider is not None
assert api.globals.clients["openai"].api_key is not None


@pytest.mark.asyncio
Expand All @@ -59,7 +59,7 @@ async def test_openai_azure_managedidentity(monkeypatch, mock_azure_credentials)
fastapi_app = api.create_app()

with TestClient(fastapi_app):
assert api.globals.clients["openai"]._azure_ad_token_provider is not None
assert api.globals.clients["openai"].api_key is not None


@pytest.mark.asyncio
Expand Down