Skip to content

Commit 9e93a0a

Browse files
Updates in post deployment script and readme files
1 parent bf6542a commit 9e93a0a

8 files changed

Lines changed: 20 additions & 60 deletions

File tree

docs/README_LOCAL.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
These variables are required:
77
- `AZURE_OPENAI_RESOURCE`
88
- `AZURE_OPENAI_MODEL`
9-
- `AZURE_OPENAI_KEY`
109

1110
These variables are optional:
1211
- `AZURE_OPENAI_TEMPERATURE`
@@ -174,6 +173,9 @@ Note: settings starting with `AZURE_SEARCH` are only needed when using Azure Ope
174173

175174
| App Setting | Value | Note |
176175
| --- | --- | ------------- |
176+
|AZURE_AI_AGENT_API_VERSION|2025-01-01-preview| API version when using the Azure Foundry agent on your data.|
177+
|AZURE_AI_AGENT_ENDPOINT||The endpoint of the Azure AI foundry project|
178+
|AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME||The name of the gpt model|
177179
|AZURE_SEARCH_SERVICE||The name of your Azure AI Search resource|
178180
|AZURE_SEARCH_INDEX||The name of your Azure AI Search Index|
179181
|AZURE_SEARCH_KEY||An **admin key** for your Azure AI Search resource|
@@ -193,7 +195,6 @@ Note: settings starting with `AZURE_SEARCH` are only needed when using Azure Ope
193195
|AZURE_OPENAI_MODEL||The name of your model deployment|
194196
|AZURE_OPENAI_ENDPOINT||The endpoint of your Azure OpenAI resource.|
195197
|AZURE_OPENAI_MODEL_NAME|gpt-35-turbo-16k|The name of the model|
196-
|AZURE_OPENAI_KEY||One of the API keys of your Azure OpenAI resource|
197198
|AZURE_OPENAI_TEMPERATURE|0|What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. A value of 0 is recommended when using your data.|
198199
|AZURE_OPENAI_TOP_P|1.0|An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. We recommend setting this to 1.0 when using your data.|
199200
|AZURE_OPENAI_MAX_TOKENS|1000|The maximum number of tokens allowed for the generated answer.|
@@ -211,6 +212,7 @@ Note: settings starting with `AZURE_SEARCH` are only needed when using Azure Ope
211212
|UI_SHOW_SHARE_BUTTON|True|Share button (right-top)
212213
|SANITIZE_ANSWER|False|Whether to sanitize the answer from Azure OpenAI. Set to True to remove any HTML tags from the response.|
213214
|USE_PROMPTFLOW|False|Use existing Promptflow deployed endpoint. If set to `True` then both `PROMPTFLOW_ENDPOINT` and `PROMPTFLOW_API_KEY` also need to be set.|
215+
|USE_AI_FOUNDRY_SDK|False|Boolean flag to determine whether to use the AI Foundry SDK instead of the OpenAI SDK.|
214216
|PROMPTFLOW_ENDPOINT||URL of the deployed Promptflow endpoint e.g. https://pf-deployment-name.region.inference.ml.azure.com/score|
215217
|PROMPTFLOW_API_KEY||Auth key for deployed Promptflow endpoint. Note: only Key-based authentication is supported.|
216218
|PROMPTFLOW_RESPONSE_TIMEOUT|120|Timeout value in seconds for the Promptflow endpoint to respond.|

infra/deploy_ai_foundry.bicep

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,6 @@ resource tenantIdEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' =
190190
}
191191
}
192192

193-
194-
resource azureOpenAIApiKeyEntry 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
195-
parent: keyVault
196-
name: 'AZURE-OPENAI-KEY'
197-
properties: {
198-
value: aiFoundry.listKeys().key1 //aiServices_m.listKeys().key1
199-
}
200-
}
201-
202193
resource azureOpenAIDeploymentModel 'Microsoft.KeyVault/vaults/secrets@2021-11-01-preview' = {
203194
parent: keyVault
204195
name: 'AZURE-OPEN-AI-DEPLOYMENT-MODEL'

infra/deploy_app_service.bicep

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ param AzureOpenAIModel string
3535
@description('Azure Open AI Endpoint')
3636
param AzureOpenAIEndpoint string = ''
3737

38-
@description('Azure OpenAI Key')
39-
@secure()
40-
param AzureOpenAIKey string
41-
4238
param azureOpenAIApiVersion string
4339
param azureOpenaiResource string = ''
4440
param USE_CHAT_HISTORY_ENABLED string = ''
@@ -235,10 +231,6 @@ resource Website 'Microsoft.Web/sites@2020-06-01' = {
235231
name: 'AZURE_OPENAI_ENDPOINT'
236232
value: AzureOpenAIEndpoint
237233
}
238-
{
239-
name: 'AZURE_OPENAI_KEY'
240-
value: AzureOpenAIKey
241-
}
242234
{
243235
name: 'AZURE_OPENAI_RESOURCE'
244236
value: azureOpenaiResource

infra/main.bicep

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ module appserviceModule 'deploy_app_service.bicep' = {
386386
AzureSearchKey: keyVault.getSecret('AZURE-SEARCH-KEY')
387387
AzureOpenAIEndpoint:aifoundry.outputs.aoaiEndpoint
388388
AzureOpenAIModel: gptModelName
389-
AzureOpenAIKey:keyVault.getSecret('AZURE-OPENAI-KEY')
390389
azureOpenAIApiVersion: azureOpenaiAPIVersion //'2024-02-15-preview'
391390
azureOpenaiResource:aifoundry.outputs.aiFoundryName
392391
aiFoundryProjectName: aifoundry.outputs.aiFoundryProjectName

infra/main.json

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.34.44.8038",
8-
"templateHash": "15193785708652143745"
8+
"templateHash": "11594891016150517886"
99
}
1010
},
1111
"parameters": {
@@ -602,7 +602,7 @@
602602
"_generator": {
603603
"name": "bicep",
604604
"version": "0.34.44.8038",
605-
"templateHash": "4081811946489579439"
605+
"templateHash": "6457856750858199317"
606606
}
607607
},
608608
"parameters": {
@@ -1059,17 +1059,6 @@
10591059
"value": "[subscription().tenantId]"
10601060
}
10611061
},
1062-
{
1063-
"type": "Microsoft.KeyVault/vaults/secrets",
1064-
"apiVersion": "2021-11-01-preview",
1065-
"name": "[format('{0}/{1}', parameters('keyVaultName'), 'AZURE-OPENAI-KEY')]",
1066-
"properties": {
1067-
"value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('aiFoundryName')), '2025-04-01-preview').key1]"
1068-
},
1069-
"dependsOn": [
1070-
"[resourceId('Microsoft.CognitiveServices/accounts', variables('aiFoundryName'))]"
1071-
]
1072-
},
10731062
{
10741063
"type": "Microsoft.KeyVault/vaults/secrets",
10751064
"apiVersion": "2021-11-01-preview",
@@ -1494,14 +1483,6 @@
14941483
"AzureOpenAIModel": {
14951484
"value": "[parameters('gptModelName')]"
14961485
},
1497-
"AzureOpenAIKey": {
1498-
"reference": {
1499-
"keyVault": {
1500-
"id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.KeyVault/vaults', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value)]"
1501-
},
1502-
"secretName": "AZURE-OPENAI-KEY"
1503-
}
1504-
},
15051486
"azureOpenAIApiVersion": {
15061487
"value": "[parameters('azureOpenaiAPIVersion')]"
15071488
},
@@ -1552,7 +1533,7 @@
15521533
"_generator": {
15531534
"name": "bicep",
15541535
"version": "0.34.44.8038",
1555-
"templateHash": "12581930310509122324"
1536+
"templateHash": "9043383413973668437"
15561537
}
15571538
},
15581539
"parameters": {
@@ -1617,12 +1598,6 @@
16171598
"description": "Azure Open AI Endpoint"
16181599
}
16191600
},
1620-
"AzureOpenAIKey": {
1621-
"type": "securestring",
1622-
"metadata": {
1623-
"description": "Azure OpenAI Key"
1624-
}
1625-
},
16261601
"azureOpenAIApiVersion": {
16271602
"type": "string"
16281603
},
@@ -1941,10 +1916,6 @@
19411916
"name": "AZURE_OPENAI_ENDPOINT",
19421917
"value": "[parameters('AzureOpenAIEndpoint')]"
19431918
},
1944-
{
1945-
"name": "AZURE_OPENAI_KEY",
1946-
"value": "[parameters('AzureOpenAIKey')]"
1947-
},
19481919
{
19491920
"name": "AZURE_OPENAI_RESOURCE",
19501921
"value": "[parameters('azureOpenaiResource')]"

infra/scripts/index_scripts/02_process_data.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from azure.search.documents import SearchClient
1010
from azure.storage.filedatalake import DataLakeServiceClient
1111
from azure.search.documents.indexes import SearchIndexClient
12+
from azure.identity import (DefaultAzureCredential,
13+
get_bearer_token_provider)
1214

1315

1416
key_vault_name = 'kv_to-be-replaced'
@@ -29,23 +31,24 @@ def get_secrets_from_kv(kv_name, secret_name):
2931

3032
search_endpoint = get_secrets_from_kv(key_vault_name, "AZURE-SEARCH-ENDPOINT")
3133
search_key = get_secrets_from_kv(key_vault_name, "AZURE-SEARCH-KEY")
32-
openai_api_key = get_secrets_from_kv(key_vault_name, "AZURE-OPENAI-KEY")
3334
openai_api_base = get_secrets_from_kv(key_vault_name, "AZURE-OPENAI-ENDPOINT")
3435
openai_api_version = get_secrets_from_kv(key_vault_name, "AZURE-OPENAI-PREVIEW-API-VERSION")
3536
deployment = get_secrets_from_kv(key_vault_name, "AZURE-OPEN-AI-DEPLOYMENT-MODEL")
3637

3738

3839
# Function: Get Embeddings
39-
def get_embeddings(text: str, openai_api_base, openai_api_version, openai_api_key):
40+
def get_embeddings(text: str, openai_api_base, openai_api_version):
4041
model_id = "text-embedding-ada-002"
42+
ad_token_provider = get_bearer_token_provider(
43+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
44+
)
4145
client = AzureOpenAI(
4246
api_version=openai_api_version,
4347
azure_endpoint=openai_api_base,
44-
api_key=openai_api_key
48+
azure_ad_token_provider=ad_token_provider
4549
)
4650

4751
embedding = client.embeddings.create(input=text, model=model_id).data[0].embedding
48-
4952
return embedding
5053

5154

@@ -123,12 +126,12 @@ def prepare_search_doc(content, document_id):
123126
chunk_id = document_id + '_' + str(chunk_num).zfill(2)
124127

125128
try:
126-
v_contentVector = get_embeddings(str(chunk), openai_api_base, openai_api_version, openai_api_key)
129+
v_contentVector = get_embeddings(str(chunk), openai_api_base, openai_api_version)
127130
except Exception as e:
128131
print(f"Error occurred: {e}. Retrying after 30 seconds...")
129132
time.sleep(30)
130133
try:
131-
v_contentVector = get_embeddings(str(chunk), openai_api_base, openai_api_version, openai_api_key)
134+
v_contentVector = get_embeddings(str(chunk), openai_api_base, openai_api_version)
132135
except Exception as e:
133136
print(f"Retry failed: {e}. Setting v_contentVector to an empty list.")
134137
v_contentVector = []

scripts/SAMPLE_DATA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Create the config.json and .env
1010
- Within the scripts folder, create a new .env file.
1111
- Copy and paste the contents from the scripts/.env.sample file.
12-
- Replace the values for `<AZURE_OPENAI_RESOURCE>` and `<AZURE_OPENAI_KEY>` with the name of the Azure OpenAI resource and either KEY 1 or KEY 2.
12+
- Replace the value for `<AZURE_OPENAI_RESOURCE>` with the name of the Azure OpenAI resource and either KEY 1 or KEY 2.
1313
- Save the .env file.
1414
- Within the scripts folder, create a config file `config.json`. The format will be a list of JSON objects, with each object specifying a configuration of local data path and target search service and index. Assuming you used "Deploy to Azure" to deploy this solution accelerator, these values can be found within the resources themselves. If you did not change the Search Index name, the default value is: promissory-notes-index. Copy and paste the following script block into the config.json file and update accordingly.
1515

src/.env.sample

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Chat
22
DEBUG=True
3+
AZURE_AI_AGENT_API_VERSION=
4+
AZURE_AI_AGENT_ENDPOINT=
5+
AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME=
36
AZURE_OPENAI_RESOURCE=
47
AZURE_OPENAI_MODEL=
5-
AZURE_OPENAI_KEY=
68
AZURE_OPENAI_MODEL_NAME=gpt-35-turbo-16k
79
AZURE_OPENAI_TEMPERATURE=0
810
AZURE_OPENAI_TOP_P=1.0

0 commit comments

Comments
 (0)