Skip to content

Commit 45572c8

Browse files
authored
Reinstate AAD on AOAI (#135)
1 parent 211ac85 commit 45572c8

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

infra/core/ai/cognitiveservices.bicep

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ param location string = resourceGroup().location
55
param tags object = {}
66
@description('The custom subdomain name used to access the API. Defaults to the value of the name parameter.')
77
param customSubDomainName string = aiServiceName
8-
param disableLocalAuth bool = false
8+
param disableLocalAuth bool = true
99
param deployments array = []
1010
param appInsightsId string
1111
param appInsightConnectionString string
@@ -51,16 +51,13 @@ resource aiServiceConnection 'Microsoft.CognitiveServices/accounts/connections@2
5151
parent: account
5252
properties: {
5353
category: 'AzureOpenAI'
54-
authType: 'ApiKey'
54+
authType: 'AAD'
5555
isSharedToAll: true
5656
target: account.properties.endpoints['OpenAI Language Model Instance API']
5757
metadata: {
5858
ApiType: 'azure'
5959
ResourceId: account.id
6060
}
61-
credentials: {
62-
key: account.listKeys().key1
63-
}
6461
}
6562
}
6663

src/api/search_index_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
model: str,
6565
deployment_name: str,
6666
embedding_endpoint: str,
67-
embed_api_key: str,
67+
embed_api_key: Optional[str],
6868
embedding_client: Optional[Any] = None
6969
) -> None:
7070
"""Constructor."""

src/gunicorn.conf.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
FileSearchTool,
2121
Tool,
2222
)
23-
from azure.ai.projects.models import ConnectionType
23+
from azure.ai.projects.models import ConnectionType, ApiKeyCredentials
2424
from azure.identity.aio import DefaultAzureCredential
2525
from azure.core.credentials_async import AsyncTokenCredential
2626

@@ -74,18 +74,11 @@ async def create_index_maybe(
7474
except ValueError as e:
7575
logger.error("Error creating index: {e}")
7676
return
77-
if aoai_connection.credentials is None or aoai_connection.credentials.api_key is None:
78-
err = "Error getting the connection to Azure Open AI service. {}"
79-
if aoai_connection is not None and (aoai_connection.key is None or aoai_connection.credentials.api_key is None):
80-
logger.error(
81-
err.format(
82-
"Please configure "
83-
f"{aoai_connection.name} to use API key."))
84-
else:
85-
logger.error(
86-
err.format("Azure Open AI service connection is absent."))
87-
return
8877

78+
embed_api_key = None
79+
if aoai_connection.credentials and isinstance(aoai_connection.credentials, ApiKeyCredentials):
80+
embed_api_key = aoai_connection.credentials.api_key
81+
8982
search_mgr = SearchIndexManager(
9083
endpoint=endpoint,
9184
credential=creds,
@@ -94,7 +87,7 @@ async def create_index_maybe(
9487
model=embedding,
9588
deployment_name=embedding,
9689
embedding_endpoint=aoai_connection.target,
97-
embed_api_key=aoai_connection.credentials.api_key
90+
embed_api_key=embed_api_key
9891
)
9992
# If another application instance already have created the index,
10093
# do not upload the documents.

0 commit comments

Comments
 (0)