Skip to content

Commit 80f80c4

Browse files
testing v4
1 parent 4680343 commit 80f80c4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

infra/scripts/index_scripts/03_cu_process_data_text.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def get_secrets_from_kv(kv_name, secret_name):
145145
ai_foundry_endpoint = get_secrets_from_kv(KEY_VAULT_NAME, "AZURE-AI-AGENT-ENDPOINT")
146146
ai_foundry_project_name = get_secrets_from_kv(KEY_VAULT_NAME, "AZURE-AI-PROJECT-NAME")
147147
azure_ai_api_version = "2024-12-01-preview"
148+
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
149+
resource_group_name = os.getenv("AZURE_RESOURCE_GROUP")
148150
print("Secrets retrieved.")
149151

150152
# Azure DataLake setup
@@ -189,11 +191,17 @@ def create_ai_foundry_client():
189191
try:
190192
credential = get_azure_credential(client_id=MANAGED_IDENTITY_CLIENT_ID)
191193

192-
# Create the base project client
194+
# Extract subscription ID and resource group from AI Foundry endpoint or use defaults
195+
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID") or "1d5876cd-7603-407a-96d2-ae5ca9a9c5f3"
196+
resource_group_name = os.getenv("AZURE_RESOURCE_GROUP") or "rg-kmgensdkR041"
197+
198+
# Create the base project client with required parameters
193199
project_client = AIProjectClient(
194200
endpoint=ai_foundry_endpoint,
195201
credential=credential,
196-
project_name=ai_foundry_project_name
202+
project_name=ai_foundry_project_name,
203+
subscription_id=subscription_id,
204+
resource_group_name=resource_group_name
197205
)
198206

199207
# Add our custom assistants wrapper to bypass the broken agents interface
@@ -216,17 +224,21 @@ def get_embeddings(text: str, ai_foundry_endpoint=None, ai_foundry_project=None)
216224
"""
217225
try:
218226
from azure.ai.inference import EmbeddingsClient
227+
from azure.identity import get_bearer_token_provider
219228

220229
# Use the AI Foundry endpoint for embeddings
221230
endpoint = ai_foundry_endpoint or ai_foundry_endpoint
222231
model_id = "text-embedding-3-small" # Updated to newer model
223232

224233
credential = get_azure_credential(client_id=MANAGED_IDENTITY_CLIENT_ID)
225234

226-
# Create AI Foundry EmbeddingsClient
235+
# Create token provider with correct scope for Azure AI services
236+
token_provider = get_bearer_token_provider(credential, "https://ai.azure.com/.default")
237+
238+
# Create AI Foundry EmbeddingsClient with token provider
227239
client = EmbeddingsClient(
228240
endpoint=f"{endpoint}/models",
229-
credential=credential,
241+
token_provider=token_provider,
230242
model=model_id
231243
)
232244

0 commit comments

Comments
 (0)