Foundry Local って何?
Foundry Localは、Microsoftが開発した軽量なローカル推論ツールで、GPUを活用して高速に大規模言語モデル(LLM)を動かすためのアプリケーションです。わずか数行のコマンドで、ローカル環境にモデルをインストールし、即座にインタラクティブなチャットが開始できます。
特長
- インストールが簡単:winget install Microsoft.FoundryLocal 一発でセットアップ完了
- 高速で軽量:小型モデルをサポートしており、数百MB程度でダウンロード&推論が完了
- ローカルで完結:インターネットを介さず、完全に手元のマシンだけで会話や推論が可能
HTTP経由の利用も可能:REST APIを使って他のアプリケーションと連携もできるため、スクリプトやツールへの組み込みがしやすいと思いました。
レポジトリ
インターラクティヴ・モードで利用する(所要時間5分)
まず、 winget install Microsoft.FoundryLocal を実行してFoundry Local をインストールします。
実行例:
PS C:\Users\tsuyo> winget install Microsoft.FoundryLocal
Found Foundry Local [Microsoft.FoundryLocal] Version 0.4.91.9885
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
This package requires the following dependencies:
- Packages
Microsoft.VCLibs.Desktop.14 [>= 14.0.33728.0]
Successfully verified installer hash
Starting package install...
██████████████████████████████ 100%
Successfully installed
次に、foundry model run phi-3.5-mini でモデルをダウンロードして実行します
実行例:
PS C:\Users\tsuyo> foundry model run phi-3.5-mini
Downloading Phi-3.5-mini-instruct-cuda-gpu...
[####################################] 100.00 % [Time remaining: about 0s] 33.2 MB/s
🕓 Loading model...
🟢 Model Phi-3.5-mini-instruct-cuda-gpu loaded successfully
Interactive Chat. Enter /? or /help for help.
Interactive mode, please enter your prompt
> what is the capital of japan?
🤖 The capital of Japan is Tokyo. It is not only the political center but also the primary economic and cultural hub of the country. Tokyo became the capital after the Emperor moved from the old capital of Kyoto in 1868 during the Meiji Restoration, and it has been the seat of government since then. The city is also renowned for its modernity, dense population, and significant contributions to technology and fashion.
> /exit
インターラクティヴ・モードで直接プロンプトを送信できるようになりました。
HTTP経由で利用する(所要時間さらに5分)
まずは、Model IDを取得するのにfoundry service listを実行して、モデルのリストを表示します。
PS C:\Users\tsuyo> foundry service list
Models running in service:
Alias Model ID
🟢 phi-3.5-mini Phi-3.5-mini-instruct-cuda-gpu
Phi-3.5-mini-instruct-cuda-gpu が Model IDなのでコピーしておきます。
次に以下のPowerShellコマンドを実行します。
$response = Invoke-RestMethod -Uri "http://localhost:5273/v1/chat/completions" -Method Post -ContentType "application/json" -Body (@{
model = "Phi-3.5-mini-instruct-cuda-gpu"
messages = @(@{ role = "user"; content = "What is the golden ratio?" })
} | ConvertTo-Json -Depth 3)
$response.choices[0].message.content
実行例:
PS C:\Users\tsuyo> $response = Invoke-RestMethod -Uri "http://localhost:5273/v1/chat/completions" -Method Post -ContentType "application/json" -Body (@{
>> model = "Phi-3.5-mini-instruct-cuda-gpu"
>> messages = @(@{ role = "user"; content = "What is the golden ratio?" })
>> } | ConvertTo-Json -Depth 3)
PS C:\Users\tsuyo>
PS C:\Users\tsuyo> $response.choices[0].message.content
The golden ratio, often denoted by the Greek letter phi (φ), is an irrational number approximately equal to 1.618033988749895. It is derived from the Fibonacci sequence, where each number is the sum of the two preceding ones, starting from 0 and 1.
Mathematically, the golden ratio is defined as the positive solution to the quadratic equation:
φ = 1 + 1/φ
Solving this, we get:
φ^2 = φ + 1
φ^2 - φ - 1 = 0
Using the quadratic formula, we find:
φ = (1 + √5)/2 ≈ 1.618033988749895
The golden ratio has many interesting properties and appears in various
モデルからの応答が確認できます。
他にも VS Code の REST Client 拡張を使って同様にリクエストを送信できます。
###
POST http://localhost:5273/v1/chat/completions
Content-Type: application/json
{
"model": "Phi-3.5-mini-instruct-cuda-gpu",
"messages": [
{
"role": "user",
"content": "What is the golden ratio?"
}
]
}
実行例:
以上。簡単ですね。
