LiteRT-LM CLI

コマンドライン インターフェース(CLI)を使用すると、コードを必要とせずにモデルをすぐにテストできます。

サポートされているプラットフォーム:

  • Linux
  • macOS
  • Windows(WSL 経由)
  • Raspberry Pi

インストール

litert-lm をシステム全体のバイナリとしてインストールします。uv が必要です。

uv tool install litert-lm-nightly

方法 2: pip

仮想環境内の標準インストール。

python3 -m venv .venv
source .venv/bin/activate
pip install litert-lm-nightly

チャット

HuggingFace からダウンロードしてモデルを実行します。

litert-lm run  \
  --from-huggingface-repo=google/gemma-3n-E2B-it-litert-lm \
  gemma-3n-E2B-it-int4 \
  --prompt="What is the capital of France?"

関数呼び出し / ツール

プリセットを使用してツールを実行できます。preset.py を作成します。

import datetime
import base64

def get_current_time() -> str:
    """Returns the current date and time."""
    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

system_instruction = "You are a helpful assistant with access to tools."
tools = [get_current_time]

プリセットで実行:

litert-lm run  \
  --from-huggingface-repo=google/gemma-3n-E2B-it-litert-lm \
  gemma-3n-E2B-it-int4 \
  --preset=preset.py

プロンプトとインタラクティブ出力の例:

> what will the time be in two hours?
[tool_call] {"arguments": {}, "name": "get_current_time"}
[tool_response] {"name": "get_current_time", "response": "2026-03-25 21:54:07"}
The current time is 2026-03-25 21:54:07.

In two hours, it will be **2026-03-25 23:54:07**.

ここで何が起こっているのか

外部情報(現在時刻など)を必要とする質問をすると、モデルはツールを呼び出す必要があることを認識します。

  1. モデルが tool_call を出力: モデルが get_current_time 関数を呼び出すための JSON リクエストを出力します。
  2. CLI Executes Tool: LiteRT-LM CLI がこの呼び出しをインターセプトし、preset.py で定義された対応する Python 関数を実行します。
  3. CLI が tool_response を送信: CLI が結果をモデルに返します。
  4. モデルが最終的な回答を生成する: モデルはツールのレスポンスを使用して、ユーザーに対する最終的な回答を計算して生成します。

この「関数呼び出し」ループは CLI 内で自動的に行われるため、複雑なオーケストレーション コードを記述することなく、ローカル LLM を Python 機能で拡張できます。

同じ機能は、PythonC++Kotlin の各 API からも利用できます。