您可以使用指令列介面 (CLI) 立即測試模型,無須編寫程式碼。
支援的平台:
- Linux
- macOS
- Windows
- Raspberry Pi
安裝
方法 1:uvx (建議用於快速測試)
立即執行 litert-lm,不必永久安裝。需要 uv。
您可以在任何 litert-lm 指令加上 uvx 前置字串,以便視需要執行指令:
uvx litert-lm run --help
方法 2:uv (永久安裝)
將 litert-lm 安裝為全系統二進位檔。需要 uv。
uv tool install litert-lm
方法 3:pip
在虛擬環境中進行標準安裝。使用 --upgrade 可確保您取得最新版本,即使先前已安裝舊版也一樣。
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade litert-lm
升級中
如要將 litert-lm 升級至最新版本:
如果使用 uvx (方法 1)
您無須採取行動,uvx 會自動執行最新版本。
如果透過 uv 安裝 (方法 2)
uv tool upgrade litert-lm
如果使用 pip 安裝 (方法 3)
啟動虛擬環境並執行下列指令:
pip install --upgrade litert-lm
即時通訊
從 HuggingFace 下載並執行模型:
litert-lm run \
--from-huggingface-repo=litert-community/gemma-4-E2B-it-litert-lm \
gemma-4-E2B-it.litertlm \
--prompt="What is the capital of France?"
🔴 新功能:多權杖預測 (MTP)
多權杖預測 (MTP) 是一項效能最佳化功能,可大幅提升解碼速度。建議您一律使用 MTP,在 GPU 後端執行所有工作。
如要在 CLI 中啟用 MTP,請使用 --enable-speculative-decoding=true 旗標:
litert-lm run \
--from-huggingface-repo=litert-community/gemma-4-E2B-it-litert-lm \
gemma-4-E2B-it.litertlm \
--backend=gpu \
--enable-speculative-decoding=true \
--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=litert-community/gemma-4-E2B-it-litert-lm \
gemma-4-E2B-it.litertlm \
--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**.
這是怎麼回事?
當您提出需要外部資訊的問題 (例如目前時間) 時,模型會辨識出需要呼叫工具。
- 模型發出
tool_call:模型會輸出 JSON 要求,呼叫get_current_time函式。 - CLI 執行工具:LiteRT-LM CLI 會攔截這項呼叫,並執行
preset.py中定義的對應 Python 函式。 - CLI 傳送
tool_response:CLI 會將結果傳回模型。 - 模型生成最終答案:模型會使用工具回覆計算並生成最終答案,提供給使用者。
這個「函式呼叫」迴圈會在 CLI 中自動執行,讓您使用 Python 功能擴增本機 LLM,不必編寫任何複雜的協調程式碼。
Python、C++ 和 Kotlin API 也提供相同功能。
解除安裝中
如要解除安裝「litert-lm」,請按照下列步驟操作:
如果使用 uvx (方法 1)
您無須採取行動,uvx 會從暫時快取執行,不會永久安裝。
如果透過 uv 安裝 (方法 2)
uv tool uninstall litert-lm
如果使用 pip 安裝 (方法 3)
pip uninstall litert-lm