Skip to content

Commit 4e14e12

Browse files
Infra changes for OpenAI API call replacement
1 parent 32d2ce4 commit 4e14e12

File tree

6 files changed

+51
-54
lines changed

6 files changed

+51
-54
lines changed

infra/main.bicep

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ param gptModelVersion string = '2024-07-18'
3333
@description('Optional. Version of the GPT model to deploy.')
3434
param embeddingModelVersion string = '2'
3535

36-
@description('Optional. API version for the Azure OpenAI service.')
37-
param azureOpenaiAPIVersion string = '2025-04-01-preview'
36+
@description('Optional. API version for the Azure AI Services.')
37+
param azureAIServicesAPIVersion string = '2025-04-01-preview'
3838

3939
@minValue(10)
4040
@description('Optional. Capacity of the GPT deployment:')
@@ -494,7 +494,6 @@ module jumpboxVM 'br/public:avm/res/compute/virtual-machine:0.15.0' = if (enable
494494
// ========== Private DNS Zones ========== //
495495
var privateDnsZones = [
496496
'privatelink.cognitiveservices.azure.com'
497-
'privatelink.openai.azure.com'
498497
'privatelink.services.ai.azure.com'
499498
'privatelink.azurewebsites.net'
500499
'privatelink.blob.${environment().suffixes.storage}'
@@ -509,22 +508,20 @@ var privateDnsZones = [
509508
// DNS Zone Index Constants
510509
var dnsZoneIndex = {
511510
cognitiveServices: 0
512-
openAI: 1
513-
aiServices: 2
514-
appService: 3
515-
storageBlob: 4
516-
storageQueue: 5
517-
storageFile: 6
518-
cosmosDB: 7
519-
keyVault: 8
520-
sqlServer: 9
521-
searchService: 10
511+
aiServices: 1
512+
appService: 2
513+
storageBlob: 3
514+
storageQueue: 4
515+
storageFile: 5
516+
cosmosDB: 6
517+
keyVault: 7
518+
sqlServer: 8
519+
searchService: 9
522520
}
523521

524522
// List of DNS zone indices that correspond to AI-related services.
525523
var aiRelatedDnsZoneIndices = [
526524
dnsZoneIndex.cognitiveServices
527-
dnsZoneIndex.openAI
528525
dnsZoneIndex.aiServices
529526
]
530527

@@ -613,11 +610,11 @@ module keyvault 'br/public:avm/res/key-vault/vault:0.12.1' = {
613610
}
614611
{
615612
name: 'AZURE-OPENAI-PREVIEW-API-VERSION'
616-
value: azureOpenaiAPIVersion
613+
value: azureAIServicesAPIVersion
617614
}
618615
{
619616
name: 'AZURE-OPENAI-ENDPOINT'
620-
value: aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API']
617+
value: aiFoundryAiServices.outputs.endpoint
621618
}
622619
{
623620
name: 'AZURE-OPENAI-EMBEDDING-MODEL'
@@ -631,6 +628,10 @@ module keyvault 'br/public:avm/res/key-vault/vault:0.12.1' = {
631628
name: 'AZURE-SEARCH-ENDPOINT'
632629
value: 'https://${aiSearchName}.search.windows.net'
633630
}
631+
{
632+
name: 'AZURE-AI-AGENT-ENDPOINT'
633+
value: aiFoundryAiServices.outputs.aiProjectInfo.apiEndpoint
634+
}
634635
]
635636
enableTelemetry: enableTelemetry
636637
}
@@ -733,10 +734,6 @@ module aiFoundryAiServices 'modules/ai-services.bicep' = if (aiFoundryAIservices
733734
name: 'ai-services-dns-zone-cognitiveservices'
734735
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.cognitiveServices]!.outputs.resourceId
735736
}
736-
{
737-
name: 'ai-services-dns-zone-openai'
738-
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.openAI]!.outputs.resourceId
739-
}
740737
{
741738
name: 'ai-services-dns-zone-aiservices'
742739
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.aiServices]!.outputs.resourceId
@@ -1110,20 +1107,20 @@ module webSite 'modules/web-sites.bicep' = {
11101107
AZURE_SEARCH_URL_COLUMN: azureSearchUrlColumn
11111108
AZURE_OPENAI_RESOURCE: aiFoundryAiServices.outputs.name
11121109
AZURE_OPENAI_MODEL: gptModelName
1113-
AZURE_OPENAI_ENDPOINT: aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API']
1110+
AZURE_OPENAI_ENDPOINT: aiFoundryAiServices.outputs.endpoint
11141111
AZURE_OPENAI_TEMPERATURE: azureOpenAITemperature
11151112
AZURE_OPENAI_TOP_P: azureOpenAITopP
11161113
AZURE_OPENAI_MAX_TOKENS: azureOpenAIMaxTokens
11171114
AZURE_OPENAI_STOP_SEQUENCE: azureOpenAIStopSequence
11181115
AZURE_OPENAI_SYSTEM_MESSAGE: azureOpenAISystemMessage
1119-
AZURE_OPENAI_PREVIEW_API_VERSION: azureOpenaiAPIVersion
1116+
AZURE_OPENAI_PREVIEW_API_VERSION: azureAIServicesAPIVersion
11201117
AZURE_OPENAI_STREAM: azureOpenAIStream
11211118
AZURE_SEARCH_QUERY_TYPE: azureSearchQueryType
11221119
AZURE_SEARCH_VECTOR_COLUMNS: azureSearchVectorFields
11231120
AZURE_SEARCH_PERMITTED_GROUPS_COLUMN: azureSearchPermittedGroupsField
11241121
AZURE_SEARCH_STRICTNESS: azureSearchStrictness
11251122
AZURE_OPENAI_EMBEDDING_NAME: embeddingModel
1126-
AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API']
1123+
AZURE_OPENAI_EMBEDDING_ENDPOINT : aiFoundryAiServices.outputs.endpoint
11271124
SQLDB_SERVER: sqlServerFqdn
11281125
SQLDB_DATABASE: sqlDbName
11291126
USE_INTERNAL_STREAM: useInternalStream
@@ -1139,7 +1136,7 @@ module webSite 'modules/web-sites.bicep' = {
11391136
USE_AI_PROJECT_CLIENT: useAIProjectClientFlag
11401137
AZURE_AI_AGENT_ENDPOINT: aiFoundryAiServices.outputs.aiProjectInfo.apiEndpoint
11411138
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME: gptModelName
1142-
AZURE_AI_AGENT_API_VERSION: azureOpenaiAPIVersion
1139+
AZURE_AI_AGENT_API_VERSION: azureAIServicesAPIVersion
11431140
AZURE_SEARCH_CONNECTION_NAME: aiSearchName
11441141
AZURE_CLIENT_ID: userAssignedIdentity.outputs.clientId
11451142
}
@@ -1344,8 +1341,8 @@ output APPLICATIONINSIGHTS_CONNECTION_STRING string = enableMonitoring
13441341
? applicationInsights!.outputs.connectionString
13451342
: ''
13461343

1347-
@description('The API version used for the Azure AI Agent service.')
1348-
output AZURE_AI_AGENT_API_VERSION string = azureOpenaiAPIVersion
1344+
@description('The API version used for the Azure AI Agent service.')
1345+
output AZURE_AI_AGENT_API_VERSION string = azureAIServicesAPIVersion
13491346

13501347
@description('The endpoint URL of the Azure AI Agent project.')
13511348
output AZURE_AI_AGENT_ENDPOINT string = aiFoundryAiServices.outputs.aiProjectInfo.apiEndpoint
@@ -1372,13 +1369,13 @@ output AZURE_COSMOSDB_DATABASE string = cosmosDbDatabaseName
13721369
output AZURE_COSMOSDB_ENABLE_FEEDBACK string = azureCosmosDbEnableFeedback
13731370

13741371
@description('The endpoint URL for the Azure OpenAI Embedding model.')
1375-
output AZURE_OPENAI_EMBEDDING_ENDPOINT string = aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API']
1372+
output AZURE_OPENAI_EMBEDDING_ENDPOINT string = aiFoundryAiServices.outputs.endpoint
13761373

13771374
@description('The name of the Azure OpenAI Embedding model.')
13781375
output AZURE_OPENAI_EMBEDDING_NAME string = embeddingModel
13791376

13801377
@description('The endpoint URL for the Azure OpenAI service.')
1381-
output AZURE_OPENAI_ENDPOINT string = aiFoundryAiServices.outputs.endpoints['OpenAI Language Model Instance API']
1378+
output AZURE_OPENAI_ENDPOINT string = aiFoundryAiServices.outputs.endpoint
13821379

13831380
@description('The maximum number of tokens for Azure OpenAI responses.')
13841381
output AZURE_OPENAI_MAX_TOKENS string = azureOpenAIMaxTokens
@@ -1387,7 +1384,7 @@ output AZURE_OPENAI_MAX_TOKENS string = azureOpenAIMaxTokens
13871384
output AZURE_OPENAI_MODEL string = gptModelName
13881385

13891386
@description('The preview API version for Azure OpenAI.')
1390-
output AZURE_OPENAI_PREVIEW_API_VERSION string = azureOpenaiAPIVersion
1387+
output AZURE_OPENAI_PREVIEW_API_VERSION string = azureAIServicesAPIVersion
13911388

13921389
@description('The Azure OpenAI resource name.')
13931390
output AZURE_OPENAI_RESOURCE string = aiFoundryAiServices.outputs.name

infra/main.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"gptModelName": {
1515
"value": "${AZURE_ENV_MODEL_NAME}"
1616
},
17-
"azureOpenaiAPIVersion": {
17+
"azureAIServicesAPIVersion": {
1818
"value": "${AZURE_ENV_MODEL_VERSION}"
1919
},
2020
"gptDeploymentCapacity": {

infra/main.waf.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"gptModelName": {
1515
"value": "${AZURE_ENV_MODEL_NAME}"
1616
},
17-
"azureOpenaiAPIVersion": {
17+
"azureAIServicesAPIVersion": {
1818
"value": "${AZURE_ENV_MODEL_VERSION}"
1919
},
2020
"gptDeploymentCapacity": {

infra/modules/dependencies.bicep

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ var builtInRoleNames = {
129129
'Microsoft.Authorization/roleDefinitions',
130130
'3b20f47b-3825-43cb-8114-4bd2201156a8'
131131
)
132-
'Cognitive Services OpenAI Contributor': subscriptionResourceId(
133-
'Microsoft.Authorization/roleDefinitions',
134-
'a001fd3d-188f-4b5d-821b-7da978bf7442'
135-
)
136-
'Cognitive Services OpenAI User': subscriptionResourceId(
137-
'Microsoft.Authorization/roleDefinitions',
138-
'5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
139-
)
140132
'Cognitive Services QnA Maker Editor': subscriptionResourceId(
141133
'Microsoft.Authorization/roleDefinitions',
142134
'f4cc2bf9-21be-47a1-bdf1-5c5804381025'

infra/scripts/index_scripts/create_search_index.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
DataLakeServiceClient,
3232
FileSystemClient,
3333
)
34-
from openai import AzureOpenAI
34+
from azure.ai.projects import AIProjectClient
3535

3636
# Get Azure Key Vault Client
3737
key_vault_name = "kv_to-be-replaced" #'nc6262-kv-2fpeafsylfd2e'
@@ -61,6 +61,7 @@
6161
openai_api_version = secret_client.get_secret("AZURE-OPENAI-PREVIEW-API-VERSION").value
6262
openai_embedding_model = secret_client.get_secret("AZURE-OPENAI-EMBEDDING-MODEL").value
6363
account_name = secret_client.get_secret("ADLS-ACCOUNT-NAME").value
64+
ai_project_endpoint = secret_client.get_secret("AZURE-AI-AGENT-ENDPOINT").value
6465

6566
# Create a search index
6667
index_client = SearchIndexClient(endpoint=search_endpoint, credential=credential)
@@ -132,15 +133,22 @@
132133

133134

134135
# Function: Get Embeddings
135-
def get_embeddings(text: str, openai_api_base, openai_api_version, azure_token_provider):
136+
def get_embeddings(text: str, ai_project_endpoint, openai_api_version, credential):
136137
model_id = openai_embedding_model or "text-embedding-ada-002"
137-
client = AzureOpenAI(
138+
139+
# Create AI Projects client
140+
project_client = AIProjectClient(
141+
endpoint=ai_project_endpoint,
142+
credential=credential,
138143
api_version=openai_api_version,
139-
azure_endpoint=openai_api_base,
140-
azure_ad_token_provider=azure_token_provider,
144+
)
145+
146+
# Get the OpenAI client from the AI Projects client
147+
openai_client = project_client.get_openai_client(
148+
api_version=openai_api_version
141149
)
142150

143-
embedding = client.embeddings.create(input=text, model=model_id).data[0].embedding
151+
embedding = openai_client.embeddings.create(input=text, model=model_id).data[0].embedding
144152

145153
return embedding
146154

@@ -260,12 +268,12 @@ def chunk_data(text):
260268

261269
try:
262270
v_contentVector = get_embeddings(
263-
d["content"], openai_api_base, openai_api_version, token_provider
271+
d["content"], ai_project_endpoint, openai_api_version, credential
264272
)
265273
except:
266274
time.sleep(30)
267275
v_contentVector = get_embeddings(
268-
d["content"], openai_api_base, openai_api_version, token_provider
276+
d["content"], ai_project_endpoint, openai_api_version, credential
269277
)
270278

271279
docs.append(

src/App/backend/common/config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ def __init__(self):
7676
"AZURE_SEARCH_CONNECTION_NAME", "foundry-search-connection"
7777
)
7878

79-
# AOAI Integration Settings
79+
# AI Project Client configuration
80+
self.USE_AI_PROJECT_CLIENT = (
81+
os.getenv("USE_AI_PROJECT_CLIENT", "True").lower() == "true"
82+
)
83+
self.AI_PROJECT_ENDPOINT = os.getenv("AZURE_AI_AGENT_ENDPOINT")
84+
85+
# AOAI Integration Settings (used via AI Project Client)
8086
self.AZURE_OPENAI_RESOURCE = os.environ.get("AZURE_OPENAI_RESOURCE")
8187
self.AZURE_OPENAI_MODEL = os.environ.get("AZURE_OPENAI_MODEL")
8288
self.AZURE_OPENAI_ENDPOINT = os.environ.get("AZURE_OPENAI_ENDPOINT")
@@ -130,12 +136,6 @@ def __init__(self):
130136
os.environ.get("SANITIZE_ANSWER", "false").lower() == "true"
131137
)
132138

133-
# AI Project Client configuration
134-
self.USE_AI_PROJECT_CLIENT = (
135-
os.getenv("USE_AI_PROJECT_CLIENT", "False").lower() == "true"
136-
)
137-
self.AI_PROJECT_ENDPOINT = os.getenv("AZURE_AI_AGENT_ENDPOINT")
138-
139139
# SQL Database configuration
140140
self.SQL_DATABASE = os.getenv("SQLDB_DATABASE")
141141
self.SQL_SERVER = os.getenv("SQLDB_SERVER")

0 commit comments

Comments
 (0)