次の方法で共有


Azure AI Foundry モデルのすべてのリソースを作成して構成する

Von Bedeutung

この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能はサポート対象ではなく、機能が制限されることがあります。 詳細については、「 Microsoft Azure プレビューの追加使用条件」を参照してください。

この記事では、プロジェクトで Azure AI Foundry モデルを使用するために必要なリソースを作成する方法について説明します。

リソースを理解する

Azure AI Foundry Models は、Azure AI Foundry Services (旧称 Azure AI Services) の機能です。 リソースに属するモデルデプロイメントを作成し、それらの予測を利用できます。 また、リソースを Azure AI Foundry の Azure AI Hubs およびプロジェクトに接続して、必要に応じてインテリジェント なアプリケーションを作成することもできます。 次の図は、高レベルアーキテクチャを示しています。

チュートリアルで作成されたリソースのアーキテクチャの概要を示す図。

Azure AI Foundry Services では、AI プロジェクトや AI ハブを運用する必要はありません。また、それらを作成してアプリケーションからフラッグシップ モデルを使用できます。 ただし、プレイグラウンドやエージェントなど、 Azure AI プロジェクトとハブをデプロイする場合は、追加の機能を使用できます。

このチュートリアルを使うと、次のことを作成できます。

  • Azure AI Foundry リソース。
  • サーバーレス API デプロイでサポートされる各モデルのモデルデプロイ。
  • (省略可能) Azure AI プロジェクトとハブ。
  • (必要に応じて)ハブと Azure AI Foundry のモデル間の接続。

[前提条件]

この記事を完了するには、以下が必要です。

リソースの作成

Azure AI Foundry (旧称 Azure AI Services) リソースを使用してプロジェクトを作成するには、次の手順に従います。

  1. Azure AI Foundry ポータルに移動します。

  2. ランディング ページ上で、[プロジェクトの作成] を選択します。

  3. プロジェクトに名前を付けます (「my-project」など)。

  4. このチュートリアルでは、新しい AI ハブのもとにまったく新しいプロジェクトを作成するため、[新しいハブの作成] を選択します。

  5. ハブに名前を付け (「my-hub」など)、[次へ] を選択します。

  6. ウィザードが更新され、作成されるリソースの詳細が表示されます。 [作成する Azure リソース] を選択して詳細を表示します。

    作成されるプロジェクトとハブの詳細を示すスクリーンショット。

  7. 次のリソースが作成されていることがわかります。

    プロパティ 説明
    リソースグループ Azure 内のすべてのリソースのメイン コンテナー。 これにより、連携して動作するリソースを整理するのに役立ちます。 また、プロジェクト全体に関連付けられているコストのスコープを設定するのにも役立ちます。
    ロケーション 作成しているリソースのリージョン。
    ハブ Azure AI Foundry 内の AI プロジェクトのメイン コンテナー。 ハブはコラボレーションを促進し、プロジェクトの情報を保存できるようになります。
    AI Foundry このチュートリアルでは、新しいアカウントが作成されますが、Azure AI Foundry Services は複数のハブとプロジェクト間で共有できます。 ハブでは、リソースへの接続を使用して、そこで使用可能なモデル デプロイにアクセスできます。 Azure AI Foundry モデルを利用するためにプロジェクトと Azure AI Foundry の間に接続を作成する方法については、AI プロジェクトの接続をご覧ください。
  8. を選択してを作成します。 リソースの作成プロセスが開始されます。

  9. 完了すると、そのプロジェクトを構成する準備が整います。

  10. Azure AI Foundry Models を使用するには、モデル デプロイを追加する必要があります。

次のステップ

Azure AI Foundry リソースで推論に使用できるモデルを決定して構成できます。 特定のモデルが構成されたら、要求でそのモデル名またはデプロイ名を指定することで、そこから予測を生成できます。 これを使用するためにコードをさらに変更する必要はありません。

この記事では、Azure AI Foundry に新しいモデルを追加する方法について説明します。

[前提条件]

この記事を完了するには、以下が必要です。

  • Azure AI サービスの Azure CLIcognitiveservices 拡張機能をインストールします。

    az extension add -n cognitiveservices
    
  • このチュートリアル内の一部のコマンドでは、ユーザーのシステムにインストールされていない場合がある jq ツールを使用します。 インストール手順については、ダウンロードjqを参照してください。

  • 次の情報を特定します。

    • Azure のサブスクリプション ID。

    • Azure AI サービス リソース名。

    • Azure AI サービス リソースがデプロイされているリソース グループ。

モデルの追加

モデルを追加するには、まずデプロイするモデルを特定する必要があります。 使用可能なモデルに対しては、次のようにクエリを実行できます。

  1. Azure サブスクリプションにログインします。

    az login
    
  2. 複数のサブスクリプションがある場合は、リソースが配置されているサブスクリプションを選択します。

    az account set --subscription $subscriptionId
    
  3. 使用する予定の Azure AI サービス リソースとリソース グループの名前を使用して、次の環境変数を設定します。

    accountName="<ai-services-resource-name>"
    resourceGroupName="<resource-group>"
    ___location="eastus2"
    
  4. Azure AI サービス アカウントをまだ作成していない場合は、次のように作成できます。

    az cognitiveservices account create -n $accountName -g $resourceGroupName --custom-___domain $accountName --___location $___location --kind AIServices --sku S0
    
  5. まず、使用可能なモデルと、どの SKU かを見てみましょう。 SKU ( デプロイの種類とも呼ばれます) は、Azure インフラストラクチャを使用して要求を処理する方法を定義します。 モデルでは、さまざまなデプロイの種類が提供される場合があります。 次のコマンドは、使用可能なすべてのモデル定義を一覧表示します。

    az cognitiveservices account list-models \
        -n $accountName \
        -g $resourceGroupName \
    | jq '.[] | { name: .name, format: .format, version: .version, sku: .skus[0].name, capacity: .skus[0].capacity.default }'
    
  6. 出力は次のようになります。

    {
      "name": "Phi-3.5-vision-instruct",
      "format": "Microsoft",
      "version": "2",
      "sku": "GlobalStandard",
      "capacity": 1
    }
    
  7. デプロイするモデルを特定します。 必要なプロパティは nameformatversionsku です。 プロパティ format は、モデルを提供するプロバイダーを示します。 デプロイの種類によっては、容量も必要になる場合があります。

  8. モデル デプロイをリソースに追加します。 次の例では、Phi-3.5-vision-instruct を追加します。

    az cognitiveservices account deployment create \
        -n $accountName \
        -g $resourceGroupName \
        --deployment-name Phi-3.5-vision-instruct \
        --model-name Phi-3.5-vision-instruct \
        --model-version 2 \
        --model-format Microsoft \
        --sku-capacity 1 \
        --sku-name GlobalStandard
    
  9. モデルを実行する準備ができました。

別のデプロイ名を付ける限り、必要に応じて、同じモデルを複数回デプロイできます。 この機能は、コンテンツ フィルターなど、特定のモデルのさまざまな構成をテストする場合に役立ちます。

モデルを使用する

デプロイされたモデルは、リソースに対する Azure AI モデルの推論エンドポイント を使用して使用できます。 要求を作成する際に、パラメーター model を指定し、作成したモデル デプロイ名を挿入します。 次のコードを使用して、推論エンドポイントの URI をプログラムで取得できます。

推論エンドポイント

az cognitiveservices account show  -n $accountName -g $resourceGroupName | jq '.properties.endpoints["Azure AI Model Inference API"]'

Azure AI Foundry Models エンドポイントに要求を行うには、ルート models ( https://<resource>.services.ai.azure.com/modelsなど) を追加します。 エンドポイントの API リファレンスについては、 Azure AI モデル推論 API リファレンス ページを参照してください。

推論キー

az cognitiveservices account keys list  -n $accountName -g $resourceGroupName

展開を管理する

CLI を使用すると、使用可能なすべてのデプロイを表示できます。

  1. 次のコマンドを実行して、アクティブなすべてのデプロイを表示します。

    az cognitiveservices account deployment list -n $accountName -g $resourceGroupName
    
  2. 特定のデプロイの詳細を表示できます。

    az cognitiveservices account deployment show \
        --deployment-name "Phi-3.5-vision-instruct" \
        -n $accountName \
        -g $resourceGroupName
    
  3. 特定のデプロイは次のように削除できます。

    az cognitiveservices account deployment delete \
        --deployment-name "Phi-3.5-vision-instruct" \
        -n $accountName \
        -g $resourceGroupName
    

Von Bedeutung

この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能はサポート対象ではなく、機能が制限されることがあります。 詳細については、「 Microsoft Azure プレビューの追加使用条件」を参照してください。

この記事では、プロジェクトで Azure AI Foundry モデルを使用するために必要なリソースを作成する方法について説明します。

リソースを理解する

Azure AI Foundry Models は、Azure AI Foundry Services (旧称 Azure AI Services) の機能です。 リソースに属するモデルデプロイメントを作成し、それらの予測を利用できます。 また、リソースを Azure AI Foundry の Azure AI Hubs およびプロジェクトに接続して、必要に応じてインテリジェント なアプリケーションを作成することもできます。 次の図は、高レベルアーキテクチャを示しています。

チュートリアルで作成されたリソースのアーキテクチャの概要を示す図。

Azure AI Foundry Services では、AI プロジェクトや AI ハブを運用する必要はありません。また、それらを作成してアプリケーションからフラッグシップ モデルを使用できます。 ただし、プレイグラウンドやエージェントなど、 Azure AI プロジェクトとハブをデプロイする場合は、追加の機能を使用できます。

このチュートリアルを使うと、次のことを作成できます。

  • Azure AI Foundry リソース。
  • サーバーレス API デプロイでサポートされる各モデルのモデルデプロイ。
  • (省略可能) Azure AI プロジェクトとハブ。
  • (必要に応じて)ハブと Azure AI Foundry のモデル間の接続。

[前提条件]

この記事を完了するには、以下が必要です。

  • Azure CLI をインストールします。

  • 次の情報を特定します。

    • Azure のサブスクリプション ID。

このチュートリアルについて

この記事の中の例は、Azure-Samples/azureai-model-inference-bicep リポジトリに含まれるサンプル コードに基づいています。 ファイル内容のコピーや貼り付けをする必要なく、ローカル環境でコマンドを実行するには、次のコマンドを使用してリポジトリをクローンし、そのコーディング言語のフォルダーに移動します。

git clone https://github.com/Azure-Samples/azureai-model-inference-bicep

この例のファイルは、次の場所にあります。

cd azureai-model-inference-bicep/infra

パートナーやコミュニティからモデルを購読するために必要なアクセス許可

デプロイに使用できるパートナーとコミュニティのモデル (Cohere モデルなど) には、Azure Marketplace が必要です。 モデル プロバイダーは、ライセンス条項を定義し、Azure Marketplace を使用してモデルを使用するための価格を設定します。

サード パーティ製モデルをデプロイする場合は、アカウントに次のアクセス許可があることを確認します。

  • Azure サブスクリプションで次の手順を実行します。
    • Microsoft.MarketplaceOrdering/agreements/offers/plans/read
    • Microsoft.MarketplaceOrdering/agreements/offers/plans/sign/action
    • Microsoft.MarketplaceOrdering/offerTypes/publishers/offers/plans/agreements/read
    • Microsoft.Marketplace/offerTypes/publishers/offers/plans/agreements/read
    • Microsoft.SaaS/register/action
  • リソース グループで、SaaS リソースを作成して使用するには、次の手順を実行します。
    • Microsoft.SaaS/resources/read
    • Microsoft.SaaS/resources/write

リソースの作成

次の手順に従います。

  1. テンプレート modules/ai-services-template.bicep を使用して、Azure AI サービス リソースについて説明します。

    modules/ai-services-template.bicep

    @description('Location of the resource.')
    param ___location string = resourceGroup().___location
    
    @description('Name of the Azure AI Services account.')
    param accountName string
    
    @description('The resource model definition representing SKU')
    param sku string = 'S0'
    
    @description('Whether or not to allow keys for this account.')
    param allowKeys bool = true
    
    @allowed([
      'Enabled'
      'Disabled'
    ])
    @description('Whether or not public endpoint access is allowed for this account.')
    param publicNetworkAccess string = 'Enabled'
    
    @allowed([
      'Allow'
      'Deny'
    ])
    @description('The default action for network ACLs.')
    param networkAclsDefaultAction string = 'Allow'
    
    resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
      name: accountName
      ___location: ___location
      identity: {
        type: 'SystemAssigned'
      }
      sku: {
        name: sku
      }
      kind: 'AIServices'
      properties: {
        customSubDomainName: accountName
        publicNetworkAccess: publicNetworkAccess
        networkAcls: {
          defaultAction: networkAclsDefaultAction
        }
        disableLocalAuth: allowKeys
      }
    }
    
    output endpointUri string = 'https://${account.outputs.name}.services.ai.azure.com/models'
    output id string = account.id
    
  2. テンプレート modules/ai-services-deployment-template.bicep を使用して、モデル デプロイについて説明します。

    modules/ai-services-deployment-template.bicep

    @description('Name of the Azure AI services account')
    param accountName string
    
    @description('Name of the model to deploy')
    param modelName string
    
    @description('Version of the model to deploy')
    param modelVersion string
    
    @allowed([
      'AI21 Labs'
      'Cohere'
      'Core42'
      'DeepSeek'
      'xAI'
      'Meta'
      'Microsoft'
      'Mistral AI'
      'OpenAI'
    ])
    @description('Model provider')
    param modelPublisherFormat string
    
    @allowed([
        'GlobalStandard'
        'DataZoneStandard'
        'Standard'
        'GlobalProvisioned'
        'Provisioned'
    ])
    @description('Model deployment SKU name')
    param skuName string = 'GlobalStandard'
    
    @description('Content filter policy name')
    param contentFilterPolicyName string = 'Microsoft.DefaultV2'
    
    @description('Model deployment capacity')
    param capacity int = 1
    
    resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2024-04-01-preview' = {
      name: '${accountName}/${modelName}'
      sku: {
        name: skuName
        capacity: capacity
      }
      properties: {
        model: {
          format: modelPublisherFormat
          name: modelName
          version: modelVersion
        }
        raiPolicyName: contentFilterPolicyName == null ? 'Microsoft.Nill' : contentFilterPolicyName
      }
    }
    
  3. 便宜上、JSON ファイルを使用して、サービス内で使用可能にするモデルを定義します。 ファイル infra/models.json には、キー nameversionprovidersku を含む JSON オブジェクトの一覧が含まれており、デプロイでプロビジョニングされるモデルが定義されています。 モデルはサーバーレス API デプロイをサポートしているため、モデル デプロイを追加しても追加コストは発生しません。 使用可能にするモデル エントリを削除または追加することでファイルを変更します。 次の例は JSON ファイルの最初の 7 行のみを表示します。

    models.json

    [
      {
        "name": "Cohere-command-a",
        "version": "1",
        "provider": "Cohere",
        "sku": "GlobalStandard"
      },
    
  4. プロジェクトを使用する (推奨) 予定の場合、プロジェクト、ハブ、Azure AI サービス リソースへの接続を作成するためのテンプレートが必要です。

    modules/project-hub-template.bicep

    param ___location string = resourceGroup().___location
    
    @description('Name of the Azure AI hub')
    param hubName string = 'hub-dev'
    
    @description('Name of the Azure AI project')
    param projectName string = 'intelligent-apps'
    
    @description('Name of the storage account used for the workspace.')
    param storageAccountName string = replace(hubName, '-', '')
    param keyVaultName string = replace(hubName, 'hub', 'kv')
    param applicationInsightsName string = replace(hubName, 'hub', 'log')
    
    @description('The container registry resource id if you want to create a link to the workspace.')
    param containerRegistryName string = replace(hubName, '-', '')
    
    @description('The tags for the resources')
    param tagValues object = {
      owner: 'santiagxf'
      project: 'intelligent-apps'
      environment: 'dev'
    }
    
    var tenantId = subscription().tenantId
    var resourceGroupName = resourceGroup().name
    var storageAccountId = resourceId(resourceGroupName, 'Microsoft.Storage/storageAccounts', storageAccountName)
    var keyVaultId = resourceId(resourceGroupName, 'Microsoft.KeyVault/vaults', keyVaultName)
    var applicationInsightsId = resourceId(resourceGroupName, 'Microsoft.Insights/components', applicationInsightsName)
    var containerRegistryId = resourceId(
      resourceGroupName,
      'Microsoft.ContainerRegistry/registries',
      containerRegistryName
    )
    
    resource storageAccount 'Microsoft.Storage/storageAccounts@2019-04-01' = {
      name: storageAccountName
      ___location: ___location
      sku: {
        name: 'Standard_LRS'
      }
      kind: 'StorageV2'
      properties: {
        encryption: {
          services: {
            blob: {
              enabled: true
            }
            file: {
              enabled: true
            }
          }
          keySource: 'Microsoft.Storage'
        }
        supportsHttpsTrafficOnly: true
      }
      tags: tagValues
    }
    
    resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' = {
      name: keyVaultName
      ___location: ___location
      properties: {
        tenantId: tenantId
        sku: {
          name: 'standard'
          family: 'A'
        }
        enableRbacAuthorization: true
        accessPolicies: []
      }
      tags: tagValues
    }
    
    resource applicationInsights 'Microsoft.Insights/components@2018-05-01-preview' = {
      name: applicationInsightsName
      ___location: ___location
      kind: 'web'
      properties: {
        Application_Type: 'web'
      }
      tags: tagValues
    }
    
    resource containerRegistry 'Microsoft.ContainerRegistry/registries@2019-05-01' = {
      name: containerRegistryName
      ___location: ___location
      sku: {
        name: 'Standard'
      }
      properties: {
        adminUserEnabled: true
      }
      tags: tagValues
    }
    
    resource hub 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' = {
      name: hubName
      kind: 'Hub'
      ___location: ___location
      identity: {
        type: 'systemAssigned'
      }
      sku: {
        tier: 'Standard'
        name: 'standard'
      }
      properties: {
        description: 'Azure AI hub'
        friendlyName: hubName
        storageAccount: storageAccountId
        keyVault: keyVaultId
        applicationInsights: applicationInsightsId
        containerRegistry: (empty(containerRegistryName) ? null : containerRegistryId)
        encryption: {
          status: 'Disabled'
          keyVaultProperties: {
            keyVaultArmId: keyVaultId
            keyIdentifier: ''
          }
        }
        hbiWorkspace: false
      }
      tags: tagValues
    }
    
    resource project 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' = {
      name: projectName
      kind: 'Project'
      ___location: ___location
      identity: {
        type: 'systemAssigned'
      }
      sku: {
        tier: 'Standard'
        name: 'standard'
      }
      properties: {
        description: 'Azure AI project'
        friendlyName: projectName
        hbiWorkspace: false
        hubResourceId: hub.id
      }
      tags: tagValues
    }
    

    modules/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
        }
      }
    }
    
  5. 主なデプロイを定義します。

    deploy-with-project.bicep

    @description('Location to create the resources in')
    param ___location string = resourceGroup().___location
    
    @description('Name of the resource group to create the resources in')
    param resourceGroupName string = resourceGroup().name
    
    @description('Name of the AI Services account to create')
    param accountName string = 'azurei-models-dev'
    
    @description('Name of the project hub to create')
    param hubName string = 'hub-azurei-dev'
    
    @description('Name of the project to create in the project hub')
    param projectName string = 'intelligent-apps'
    
    @description('Path to a JSON file with the list of models to deploy. Each model is a JSON object with the following properties: name, version, provider')
    var models = json(loadTextContent('models.json'))
    
    module aiServicesAccount 'modules/ai-services-template.bicep' = {
      name: 'aiServicesAccount'
      scope: resourceGroup(resourceGroupName)
      params: {
        accountName: accountName
        ___location: ___location
      }
    }
    
    module projectHub 'modules/project-hub-template.bicep' = {
      name: 'projectHub'
      scope: resourceGroup(resourceGroupName)
      params: {
        hubName: hubName
        projectName: projectName
      }
    }
    
    module aiServicesConnection 'modules/ai-services-connection-template.bicep' = {
      name: 'aiServicesConnection'
      scope: resourceGroup(resourceGroupName)
      params: {
        name: accountName
        authType: 'AAD'
        endpointUri: aiServicesAccount.outputs.endpointUri
        resourceId: aiServicesAccount.outputs.id
        hubName: hubName
      }
      dependsOn: [
        projectHub
      ]
    }
    
    @batchSize(1)
    module modelDeployments 'modules/ai-services-deployment-template.bicep' = [
      for (item, i) in models: {
        name: 'deployment-${item.name}'
        scope: resourceGroup(resourceGroupName)
        params: {
          accountName: accountName
          modelName: item.name
          modelVersion: item.version
          modelPublisherFormat: item.provider
          skuName: item.sku
        }
        dependsOn: [
          aiServicesAccount
        ]
      }
    ]
    
    output endpoint string = aiServicesAccount.outputs.endpointUri
    
  6. Azure にログインします。

    az login
    
  7. 適切なサブスクリプションを使用していることを確認します。

    az account set --subscription "<subscription-id>"
    
  8. デプロイを実行します。

    RESOURCE_GROUP="<resource-group-name>"
    
    az deployment group create \
      --resource-group $RESOURCE_GROUP \
      --template-file deploy-with-project.bicep
    
  9. Azure AI サービス リソースとモデル デプロイのみをデプロイする場合は、次のデプロイ ファイルを使用します。

    deploy.bicep

    @description('Location to create the resources in')
    param ___location string = resourceGroup().___location
    
    @description('Name of the resource group to create the resources in')
    param resourceGroupName string = resourceGroup().name
    
    @description('Name of the AI Services account to create')
    param accountName string = 'azurei-models-dev'
    
    @description('Path to a JSON file with the list of models to deploy. Each model is a JSON object with the following properties: name, version, provider')
    var models = json(loadTextContent('models.json'))
    
    module aiServicesAccount 'modules/ai-services-template.bicep' = {
      name: 'aiServicesAccount'
      scope: resourceGroup(resourceGroupName)
      params: {
        accountName: accountName
        ___location: ___location
      }
    }
    
    @batchSize(1)
    module modelDeployments 'modules/ai-services-deployment-template.bicep' = [
      for (item, i) in models: {
        name: 'deployment-${item.name}'
        scope: resourceGroup(resourceGroupName)
        params: {
          accountName: accountName
          modelName: item.name
          modelVersion: item.version
          modelPublisherFormat: item.provider
          skuName: item.sku
        }
        dependsOn: [
          aiServicesAccount
        ]
      }
    ]
    
    output endpoint string = aiServicesAccount.outputs.endpointUri
    
  10. デプロイを実行します。

    RESOURCE_GROUP="<resource-group-name>"
    
    az deployment group create \
      --resource-group $RESOURCE_GROUP \
      --template-file deploy.bicep
    
  11. このテンプレートは、作成したモデルのデプロイメントを使用するために利用できる Azure AI Foundry モデルのエンドポイントを出力します。

次のステップ