Microsoft Learnの「Explore the components and tools of the Azure AI Foundry」を参照して、LLMを使ってみました。
前提
- Azureでサブスクリプションとリソースグループは作成済(Namingは「Define your naming convention」参照)
Step
1. プロジェクト作成
Azure AI Foundryを開いて「プロジェクト作成」ボタンクリック
※ Sign Inなどは省略
プロジェクト名は提案されたものをそのままにして、「カスタマイズ」ボタンクリック
以下の項目のみ変更して作成
Azure Portalでリソースグループ内の以下のリソース作成を確認。
2. モデルデプロイ
左のナビゲーションメニューで、マイアセット -> モデル+エンドポイントを選択し、コンテンツエリアで +モデルのデプロイ -> 基本モデルをデプロイする をクリック
3. Playgroundでテスト
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?
モデル名はデプロイした"gpt-4o-mini"にしています。