配置连接以在 AI 项目中使用 Azure AI Foundry 模型

可以在 Azure AI Foundry 的项目中使用 Azure AI Foundry 模型来创建访问应用程序并交互/管理可用的模型。 若要在项目中使用 Azure AI Foundry 模型服务,需要创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接。

以下文章介绍如何创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接,以使用 Azure AI Foundry 模型。

先决条件

若要完成本文,需要做好以下准备:

  • AI 项目资源。

  • 模型部署到 Azure AI 模型推理服务 功能已启用。

    演示如何在 Azure AI Foundry 门户中启用“将模型部署到 Azure AI 模型推理服务”功能的动画。

添加连接

可以使用以下步骤创建与 Azure AI 服务资源的连接:

  1. 转到 Azure AI Foundry 门户

  2. 在屏幕左下角,选择“管理中心”

  3. 在“连接”部分中,选择“新建连接”。

  4. 选择“Azure AI 服务”

  5. 在浏览器中,在订阅中查找现有的 Azure AI 服务资源。

  6. 选择“添加连接”。

  7. 新连接将添加到你的中心。

  8. 返回到项目的登陆页面以继续,现在选择新建的连接。 如果页面未立即显示,请刷新该页面。

    项目的登陆页的屏幕截图,其中突出显示已连接资源的位置和已关联的推理终结点。

查看已连接资源中的模型部署

可以按照以下步骤查看已连接资源中可用的模型部署:

  1. 转到 Azure AI Foundry 门户

  2. 在左窗格中,选择 “模型 + 终结点”。

  3. 该页显示可用的模型部署,按连接名称分组。 找到刚刚创建的连接,该连接应属于 Azure AI 服务类型。

    显示给定连接下可用的模型的列表的屏幕截图。

  4. 选择要检查的任何模型部署。

  5. 详细信息页显示有关特定部署的信息。 如果要测试模型,可以使用“在操场中打开”的选项。

  6. 将显示 Azure AI Foundry 操场,可在其中与给定模型进行交互。

可以在 Azure AI Foundry 的项目中使用 Azure AI Foundry 模型来创建访问应用程序并交互/管理可用的模型。 若要在项目中使用 Azure AI Foundry 模型服务,需要创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接。

以下文章介绍如何创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接,以使用 Azure AI Foundry 模型。

先决条件

若要完成本文,需要做好以下准备:

  • 安装适用于 Azure AI Foundry 的 Azure CLIml 扩展:

    az extension add -n ml
    
  • 标识以下信息:

    • Azure 订阅 ID。

    • 你的 Azure AI 服务资源名称。

    • 在其中部署 Azure AI 服务资源的资源组。

添加连接

若要添加模型,首先需要标识要部署的模型。 可以按如下所示的方法查询可用模型:

  1. 登录到 Azure 订阅:

    az login
    
  2. 将 CLI 配置为指向该项目:

    az account set --subscription <subscription>
    az configure --defaults workspace=<project-name> group=<resource-group> ___location=<___location>
    
  3. 创建连接定义:

    connection.yml

    name: <connection-name>
    type: aiservices
    endpoint: https://<ai-services-resourcename>.services.ai.azure.com
    api_key: <resource-api-key>
    
  4. 创建连接:

    az ml connection create -f connection.yml
    
  5. 此时,连接可供使用。

可以在 Azure AI Foundry 的项目中使用 Azure AI Foundry 模型来创建访问应用程序并交互/管理可用的模型。 若要在项目中使用 Azure AI Foundry 模型服务,需要创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接。

以下文章介绍如何创建与 Azure AI Foundry 资源(以前已知的 Azure AI 服务)的连接,以使用 Azure AI Foundry 模型。

先决条件

若要完成本文,需要做好以下准备:

  • 具有 AI 中心的 Azure AI 项目。

  • 安装 Azure CLI

  • 标识以下信息:

    • Azure 订阅 ID。

    • 你的 Azure AI 服务资源名称。

    • 你的 Azure AI 服务资源 ID。

    • 部署项目的 Azure AI 中心的名称。

    • 在其中部署 Azure AI 服务资源的资源组。

添加连接

  1. 使用模板 ai-services-connection-template.bicep 描述连接:

    ai-services-connection-template.bicep

    @description('Name of the hub where the connection will be created')
    param hubName string
    
    @description('Name of the connection')
    param name string
    
    @description('Category of the connection')
    param category string = 'AIServices'
    
    @allowed(['AAD', 'ApiKey', 'ManagedIdentity', 'None'])
    param authType string = 'AAD'
    
    @description('The endpoint URI of the connected service')
    param endpointUri string
    
    @description('The resource ID of the connected service')
    param resourceId string = ''
    
    @secure()
    param key string = ''
    
    
    resource connection 'Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview' = {
      name: '${hubName}/${name}'
      properties: {
        category: category
        target: endpointUri
        authType: authType
        isSharedToAll: true
        credentials: authType == 'ApiKey' ? {
          key: key
        } : null
        metadata: {
          ApiType: 'Azure'
          ResourceId: resourceId
        }
      }
    }
    
  2. 运行部署:

    RESOURCE_GROUP="<resource-group-name>"
    ACCOUNT_NAME="<azure-ai-model-inference-name>" 
    ENDPOINT_URI="https://<azure-ai-model-inference-name>.services.ai.azure.com"
    RESOURCE_ID="<resource-id>"
    HUB_NAME="<hub-name>"
    
    az deployment group create \
        --resource-group $RESOURCE_GROUP \
        --template-file ai-services-connection-template.bicep \
        --parameters accountName=$ACCOUNT_NAME hubName=$HUB_NAME endpointUri=$ENDPOINT_URI resourceId=$RESOURCE_ID
    

后续步骤