次の方法で共有


Bicep を使用して Azure OpenAI サービスをデプロイする

AIShell では、openai-gpt エージェントをパブリック OpenAI インスタンスまたは Azure OpenAI デプロイと共に使用できます。 Azure OpenAI サービスには追加の機能があり、管理性が向上するため、使用することをお勧めします。 この記事では、Bicep を使用して Azure OpenAI サービスをデプロイおよびインスタンス化する手順について説明します。

Azure OpenAI サービスで AIShell を使用するには、次の Azure リソースが必要です。

  • Azure OpenAI サービス アカウント - 複数の異なるモデル デプロイを含むリソース。
  • Azure OpenAI デプロイ - API を使用して応答を生成するために呼び出すことができるモデル デプロイ。

前提 条件

開始する前に、次の前提条件を満たしていることを確認してください。

  • アクティブな Azure サブスクリプション
  • Azure CLI を するか、ローカルにインストールされている Azure PowerShell を するか、Azure Cloud Shell にアクセスする
  • Azure サブスクリプションにリソースを作成するための適切なアクセス許可

デプロイの手順

これらの手順では、次のタスクについて説明します。

  1. Bicep ファイルをダウンロードして変更する
  2. Azure OpenAI サービスをデプロイする
  3. デプロイを使用するようにエージェントを構成する

1. Bicep ファイルをダウンロードして変更する

main.bicep ファイルを AIShell リポジトリからダウンロードします。

独自の値を含めるには、./main.bicep ファイルの先頭にあるパラメーターを変更する必要があります。 山かっこ (< >) のプレースホルダーを独自の値に置き換えます。

@description('This is the name of your AI Service Account')
param aiserviceaccountname string = '<Insert own account name>'

@description('Custom domain name for the endpoint')
param customDomainName string = '<Insert own unique domain name>'

@description('Name of the deployment')
param modeldeploymentname string = '<Insert own deployment name>'

@description('The model being deployed')
param model string = 'gpt-4'

@description('Version of the model being deployed')
param modelversion string = 'turbo-2024-04-09'

@description('Capacity for specific model used')
param capacity int = 80

@description('Location for all resources.')
param location string = resourceGroup().location

@allowed([
  'S0'
])
param sku string = 'S0'

このデプロイでは、Bicep ファイルでは次の既定値が使用されます。

  • Azure OpenAI アカウントの場所がリソース グループの場所に設定されている
  • AI モデルはバージョン turbo-2024-04-09gpt-4

これらの設定は、特定のニーズに合わせて変更できます。 使用可能なモデルの詳細については、「Azure OpenAI Service モデルの」を参照してください。 使用するモデルに基づいてデプロイの容量を変更することが必要になる場合があります。 容量の設定の詳細については、「Azure OpenAI Service のクォータと制限を参照してください。

2. Azure OpenAI サービスをデプロイする

Bicep ファイルパラメーターを変更したら、独自の Azure OpenAI インスタンスをデプロイする準備ができました。 Azure CLI または Azure PowerShell を使用して、Bicep ファイルをデプロイできます。

Azure CLI を使用してデプロイする

次の Azure CLI コマンドを使用して、Azure OpenAI サービスをデプロイします。 次のコマンドは、Bash セッションで実行することを目的としています。 山かっこ (< >) のプレースホルダーを独自の値に置き換えます。

コマンドは、ローカルまたは Azure Cloud Shell で実行できます。 ローカルで実行する場合は、az login を使用して Azure アカウントにサインインし、az account set --subscription <subscription name>を使用してサブスクリプションを設定する必要があります。

az deployment group create \
    --resource-group '<resource group name>' \
    --template-file ./main.bicep

# Get the endpoint and key of the deployment
az cognitiveservices account show \
    --name '<account name>'
    --resource-group '<resource group name>' | jq -r .properties.endpoint

az cognitiveservices account keys list \
    --name '<account name>' \
    --resource-group  '<resource group name>' | jq -r .key1

Azure PowerShell を使用してデプロイする

次の Azure PowerShell コマンドを使用して、Azure OpenAI サービスをデプロイします。 山かっこ (< >) のプレースホルダーを独自の値に置き換えます。

コマンドは、ローカルまたは Azure Cloud Shell で実行できます。 ローカルで実行する場合は、Connect-AzAccount を使用して Azure アカウントにサインインし、Set-AzContext -SubscriptionId <subscription id>を使用してサブスクリプションを設定する必要があります。

$AzResourceGroupDeploymentSplat = @{
    ResourceGroupName = '<resource group name>'
    TemplateFile = './main.bicep'
}
New-AzResourceGroupDeployment @AzResourceGroupDeploymentSplat

# Get the endpoint and key of the deployment
$AzCognitiveServicesAccountSplat = @{
    ResourceGroupName = '<resource group name>'
    Name = '<account name>'
}
Get-AzCognitiveServicesAccount @AzCognitiveServicesAccountSplat  |
    Select-Object -Property Endpoint

Get-AzCognitiveServicesAccountKey @AzCognitiveServicesAccountSplat |
    Select-Object -Property Key1

3. デプロイを使用するようにエージェントを構成する

デプロイのエンドポイントとキーが作成されたので、openai-gpt エージェントを構成する必要があります。 構成は JSON ファイルに格納されます。

JSON 構成を編集するには、次の手順に従います。

  1. AIShell を起動し、エージェントの一覧から openai-gpt エージェントを選択します。

  2. AIShell コマンド プロンプトで、/agent config コマンドを実行します。 このコマンドを実行すると、JSON 構成ファイルが開きます。

  3. JSON ファイルの山かっこ (< >) のプレースホルダーの値を、Azure OpenAI デプロイから取得したエンドポイントとキー値に置き換えます。 次の JSON は、更新する構成設定の例を示しています。

    {
      // Declare GPT instances.
      "GPTs": [
          {
            "Name": "ps-az-gpt4",
            "Description": "<insert description here>",
            "Endpoint": "<insert endpoint here>",
            "Deployment": "<insert deployment name here>",
            "ModelName": "gpt-4",
            "Key": "<insert key here>",
            "SystemPrompt": "1. You are a helpful and friendly assistant with expertise in PowerShell scripting and command line.\n2. Assume user is using the operating system `osx` unless otherwise specified.\n3. Use the `code block` syntax in markdown to encapsulate any part in responses that is code, YAML, JSON or XML, but not table.\n4. When encapsulating command line code, use '```powershell' if it's PowerShell command; use '```sh' if it's non-PowerShell CLI command.\n5. When generating CLI commands, never ever break a command into multiple lines. Instead, always list all parameters and arguments of the command on the same line.\n6. Please keep the response concise but to the point. Do not overexplain."
          }
      ],
      // Specify the default GPT instance to use for user query.
      // For example: "ps-az-gpt4"
      "Active": "ps-az-gpt4"
    }
    
  4. JSON ファイルを保存し、エディターを閉じます。

結論

Azure OpenAI サービスを正常にデプロイし、デプロイと通信するように openai-gpt エージェントを構成しました。 Azure OpenAI デプロイのモデル トレーニング、フィルター、および設定の詳細については、Azure OpenAI Service のドキュメント参照してください。

手記

Bicep ファイルを使用して Azure OpenAI サービスをデプロイする方法に関する彼のガイダンスをセバスチャン Jensen に感謝します。 この記事は、Medium に関するブログ記事から着想を得て、許可を得て使用されました。 彼の元の投稿を読むのに少し時間がかかる: Bicepを介して LLM デプロイを使用して Azure OpenAI サービスをデプロイします。