My Notes on the LLM CLI Tool
ai
cli
tools
tutorial
The LLM CLI tool by Simon Willison provides a simple yet powerful way to interact with various language models directly from your command line. This guide covers installation, configuration, and practical usage patterns to help you get started with this versatile tool.
Links
- GitHub: https://github.com/simonw/llm
- Documentation: https://llm.datasette.io/en/stable/
Installation
Using uv:
uv tool install llm
Plugin Installation
Install plugins for specific providers (using Azure as example):
llm install llm-azure
- llm-azure: https://github.com/fabge/llm-azure
API Key Configuration
Set your API key:
llm keys set azure
Azure Setup
Add a configuration file to the required azure
directory of llm installation:
dirname $(llm logs path)
The configuration file should look like:
- model_id: gpt-4-32k
model_name: gpt-4-32k
api_base: https://your_deployment.openai.azure.com/
api_version: '2023-05-15'
- model_id: text-embedding-3-small
embedding_model: true
model_name: text-embedding-3-small
api_base: https://your_deployment.openai.azure.com/
api_version: '2023-05-14'
model_id
: Used by the LLM CLImodel_name
: Passed to the Azure API
Set Default Model
llm models default <model_id>
Using LLM Prompts
Pipe Input
cat my_python_script.py | llm "explain this code"
Attachments
llm "describe this image" -a https://static.simonwillison.net/static/2024/pelicans.jpg
Supports both URLs and file paths.
System Prompts
echo "import fastapi" | llm "explain this code" -s "You are a python expert and explain complex concepts concisely with simple examples"
Templates
List Templates
llm templates
Edit Templates
llm templates edit summarize
Provide default values for parameters:
prompt: 'Translate to $language: $input'
defaults:
language: 中文
Use Templates
llm -t translate -p language '中文' "I love you"