1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure AI FoundryでLLMを使ってみる

Posted at

Microsoft Learnの「Explore the components and tools of the Azure AI Foundry」を参照して、LLMを使ってみました。

前提

  1. Azureでサブスクリプションとリソースグループは作成済(Namingは「Define your naming convention」参照)

Step

1. プロジェクト作成

Azure AI Foundryを開いて「プロジェクト作成」ボタンクリック
※ Sign Inなどは省略
image.png

プロジェクト名は提案されたものをそのままにして、「カスタマイズ」ボタンクリック
image.png

以下の項目のみ変更して作成

  • リソースグループ: 事前作成しておいたものに変更
  • 場所: 「選択に関するヘルプ」をクリックして、gpt-4o-miniを使うことにしたら提案された「East US」を選択
    image.png

これにより以下のリソースが作成されます。
image.png

Azure Portalでリソースグループ内の以下のリソース作成を確認。
image.png

2. モデルデプロイ

左のナビゲーションメニューで、マイアセット -> モデル+エンドポイントを選択し、コンテンツエリアで +モデルのデプロイ -> 基本モデルをデプロイする をクリック
image.png

gpt-4o-miniを選択して、「確認」ボタンクリック
image.png

デプロイ詳細項目を特に変えずにデプロイします。
image.png

3. Playgroundでテスト

「プレイグラウンドで開く」ボタンをクリック
image.png

これでチャットのテストができるようになりました。
image.png

4. Pythonから利用

こちらを見て実行。

4.1. Python環境

以下の環境で動かしています。

種類 バージョン 備考
OS Mac15.1.1
Python 3.13.1
Pyenv 2.4.23 あんま関係ないですが
Azure CLI 2.67.0

Pythonの追加パッケージ

種類 バージョン 備考
azure-ai-projects 1.0.0b4
azure-identity 1.19.0
azure-ai-inference 1.0.0b6
jupyterlab 4.3.4

4.2. ログイン

Shellでログイン

az login

4.3. プログラム実行

Jupyterで実行しています。

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

project_connection_string="<プロジェクト接続文字列>"

project = AIProjectClient.from_connection_string(
  conn_str=project_connection_string,
  credential=DefaultAzureCredential())

# get an chat inferencing client using the project's default model inferencing endpoint
chat = project.inference.get_chat_completions_client()

# run a chat completion using the inferencing client
response = chat.complete(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Hi"},
    ]
)

print(response.choices[0].message.content)
結果
Hello! How can I assist you today?

プロジェクト接続文字列はプロジェクト概要画面にあります。
image.png

モデル名はデプロイした"gpt-4o-mini"にしています。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?