-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-agent-to-foundry.ps1
More file actions
30 lines (30 loc) · 1.44 KB
/
Copy pathdeploy-agent-to-foundry.ps1
File metadata and controls
30 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$MANAGED_IDENTITY_RESOURCE_ID
$AZURE_RESOURCE_GROUP
$AI_FOUNDATION_PROJECT_NAME
$AI_FOUNDATION_ACCOUNT_NAME
$GPT_MODEL_NAME
Write-Output \"Starting AI Foundry Agent creation using REST API...\"
az login --identity --resource-id $MANAGED_IDENTITY_RESOURCE_ID
Write-Output \"Successfully logged in with managed identity.\"
$foundryAccessToken = az account get-access-token --resource 'https://ai.azure.com' | jq -r .accessToken | tr -d '\"'
Write-Output \"Access token for AI Foundry: $foundryAccessToken\"
$cognitiveAccountEndpoint = az cognitiveservices account show --name $foundryAccountNameUniqueSuffix --resource-group $resourceGroupName --query 'properties.endpoints.\"AI Foundry API\"' -o tsv
Write-Output \"Cognitive Account Endpoint: $cognitiveAccountEndpoint\"
$projectEndpoint = $cognitiveAccountEndpoint+\"api/projects/$aiFoundryProjectName\"
Write-Output \"Project Endpoint: $projectEndpoint\"
$Headers = @{
\"Authorization\" = \"Bearer $foundryAccessToken\"
\"Content-Type\" = \"application/json\"
}
$Body = @{
\"instructions\" = $instructions
\"name\" = $agentName
\"model\" = $gptModelName
} | ConvertTo-Json
$result = Invoke-WebRequest -Uri \"$projectEndpoint/assistants?api-version=$apiVersion\" -Method Post -Headers $Headers -Body $Body
Write-Output \"Result: $result\"
$resultContentJson = $result.Content | ConvertFrom-Json
Write-Output $resultContentJson
$agentId = $resultContentJson.id
Write-Output \"Agent ID: $agentId\"
return $agentId