使用AZAPI部署Azure AI Foundry在线端点时,如何获取部署模型的codeid与environmentid?
获取Azure AI Foundry部署的codeId与environmentId方法
针对你使用公共注册表中cohere-command-a模型的场景,可通过以下途径获取所需的codeId和environmentId:
一、通过Azure ML CLI获取
1. 获取codeId
执行以下命令,返回结果中的id字段即为codeId:
az ml code show --name cohere-command-a-code --version 1 --registry-name azureml
2. 获取environmentId
执行以下命令,返回结果中的id字段即为environmentId:
az ml environment show --name cohere-command-a-env --version 1 --registry-name azureml
二、通过Azure AI Studio门户获取
- 登录Azure AI Studio,导航到模型注册表,选择公共注册表
azureml。 - 找到目标模型
cohere-command-a并进入详情页。 - 在模型详情的关联资源区域,分别复制配套代码资产和环境资产的资源ID,即为所需的
codeId和environmentId。
三、在Terraform中通过数据源自动引用(推荐)
添加azapi_resource数据源自动获取公共资产ID,避免手动复制:
# 获取公共代码资产ID data "azapi_resource" "cohere_code" { type = "Microsoft.MachineLearningServices/registries/codes@2025-01-01-preview" name = "cohere-command-a-code" parent_id = "/subscriptions/你的订阅ID/resourceGroups/你的资源组名称/providers/Microsoft.MachineLearningServices/registries/azureml" } # 获取公共环境资产ID data "azapi_resource" "cohere_env" { type = "Microsoft.MachineLearningServices/registries/environments@2025-01-01-preview" name = "cohere-command-a-env" parent_id = "/subscriptions/你的订阅ID/resourceGroups/你的资源组名称/providers/Microsoft.MachineLearningServices/registries/azureml" }
在部署资源中引用这些数据源的ID:
resource "azapi_resource" "online_endpoint_deployment" { # 其他配置保持不变 body = { sku = { capacity = 1 name = "Standard_DS3_v2" } properties = { endpointComputeType = "Managed" scaleSettings = { scaleType = "Default" } model = "azureml://registries/azureml-cohere/models/cohere-command-a/versions/1" codeConfiguration = { codeId = data.azapi_resource.cohere_code.id scoringScript = "score.py" } environmentId = data.azapi_resource.cohere_env.id } } }
内容的提问来源于stack exchange,提问作者Bokambo
相关产品推荐
相关产品推荐

