LLM CLI 도구 사용법 가이드(요약)
https://llm.datasette.io/ 공식 문서 기반
개요
LLM은 OpenAI, Anthropic Claude, Google Gemini, Meta Llama 등 다수의 대형 언어 모델과 상호작용하기 위한 CLI 도구 및 Python 라이브러리입니다. 원격 API와 로컬 모델 모두 지원합니다.
설치
# pip로 설치
pip install llm
# Homebrew로 설치
brew install llm
# uv로 설치
uv tool install llm
API 키 설정
# OpenAI 키 설정
llm keys set openai
# 또는 값을 직접 전달
llm keys set openai --value "your-api-key"
# NVIDIA 키 설정 예시
llm keys set nvidia --value "nvapi-..."
# 키 목록 확인
llm keys
환경 변수로도 설정 가능:
export OPENAI_API_KEY="your-key"
export NVIDIA_API_KEY="nvapi-..."
기본 사용법
프롬프트 실행
# 기본 실행 (기본 모델: gpt-4o-mini)
llm "Ten fun names for a pet pelican"
# 모델 지정 (-m/--model)
llm "Ten names for cheesecakes" -m gpt-4o
# 짧은 별칭 사용
llm "Hello" -m 4o
# 검색어로 모델 선택 (-q)
llm "Hello" -q 4o -q mini
파이프 입력
# 파일 내용을 파이프로 전달
cat myscript.py | llm "explain this code"
# curl과 함께 사용
curl -s 'https://example.com/article' | llm -s 'Summarize this'
# git diff 설명
git diff | llm -s 'Describe these changes'
파일 프롬프트 활용
템플릿 사용
템플릿은 프롬프트, 시스템 프롬프트, 모델, 옵션 등을 재사용 가능한 단위로 저장합니다.
# 템플릿 생성 (--save)
llm '$input - summarize this' --save summarize
# 템플릿 사용 (-t)
curl -s https://example.com/ | llm -t summarize
# 템플릿에 모델 지정
llm --system 'Summarize this' --model gpt-4o --save summarize
# 옵션 포함 저장
llm --system 'Speak in French' -o temperature 1.8 --save wild-french
# 템플릿 목록
llm templates
# 템플릿 편집
llm templates edit summarize
# 템플릿 경로 확인
llm templates path
템플릿 YAML 형식
템플릿은 YAML 파일로 저장됩니다:
# 기본 예시
prompt: 'Summarize this: $input'
# 멀티라인 프롬프트
prompt: >
Summarize the following text.
Insert frequent satirical steampunk-themed illustrative anecdotes.
Text to summarize: $input
# 시스템 프롬프트 + 일반 프롬프트
system: You speak like an excitable Victorian adventurer
prompt: 'Summarize this: $input'
# 옵션 포함
system: Speak in French
options:
temperature: 1.8
# 도구 포함
tools:
- llm_time
# 변수 기본값
system: Summarize this text in the voice of $voice
defaults:
voice: GlaDOS
프래그먼트 사용
프래그먼트는 템플릿에 외부 콘텐츠를 포함하는 방법입니다.
# 프래그먼트 포함 (-f)
llm "Summarize this document" -f document.txt
# URL 프래그먼트
llm "Analysis this" -f https://example.com/article
# 여러 프래그먼트
llm "Compare these" -f file1.txt -f file2.txt
템플릿 YAML에서 프래그먼트:
fragments:
- https://example.com/robots.txt
- /path/to/file.txt
- 993fd38d898d2b59fd2d16c811da5bdac658faa34f0f4d411edde7c17ebb0680
모델 옵션
옵션 지정 (-o/--option)
# Temperature 설정
llm "Hello" -o temperature 1.5
# 사용 가능한 옵션 확인
llm models --options
기본 옵션 설정
llm models options set gpt-4o temperature 1.2
모델별 기본값 설정
환경 변수 사용:
export LLM_MODEL=gpt-4.1-mini
llm "Hello" # 기본으로 gpt-4.1-mini 사용
웹 문서 참조
-a 옵션으로 URL이나 파일 경로를 첨부할 수 있습니다:
# 이미지 URL 첨부
llm "describe this image" -a https://example.com/image.jpg
# 로컬 파일 첨부
llm "extract text" -a scanned-document.jpg
# 여러 첨부
llm "compare these" -a image1.jpg -a image2.jpg
# 파이프로 첨부 (타입 지정)
cat myfile | llm "describe this image" --at - image/jpeg
시스템 프롬프트
# -s/--system 옵션
llm 'SQL to calculate total sales' \
--system 'You are an exaggerated sentient cheesecake'
# 파이프와 함께
curl -s 'https://example.com/article' | \
llm -s 'Suggest topics as JSON array'
대화 이어가기
# 이전 대화 계속 (-c)
llm "Tell me more" -c
# 채팅 모드 시작
llm chat -m gpt-4.1
# 이전 대화로 채팅 계속
llm chat -c
스키마 (구조화된 출력)
# 간결한 스키마 구문
llm --schema 'name,bio' 'invent a dog'
# 여러 항목
llm --schema-multi 'name,bio' 'invent two dogs'
# JSON 스키마 직접
llm --schema '{
"type": "object",
"properties": {
"dogs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"bio": {"type": "string"}
}
}
}
}
}' -m gpt-4o-mini 'invent two dogs'
# 파일에서 스키마 로드
llm --schema dog.schema.json 'invent a dog'
# 템플릿에 스키마 저장
llm --schema dog.schema.json 'invent a dog' --save dog
도구 (Tools)
인라인 Python 함수
llm --functions '
def multiply(x: int, y: int) -> int:
"""Multiply two numbers."""
return x * y
' 'what is 34234 * 213345'
플러그인 도구 사용
# 도구 목록
llm tools
# 도구 사용 (-T)
llm -T simple_eval "4444 * 233423" --td
# 계속 대화에서 도구 재사용
llm -T simple_eval "12345 * 12345" --td
llm -c "that * 6" --td # 동일한 도구 사용
OpenAI 호환 모델 설정
extra-openai-models.yaml 파일에 OpenAI 호환 API 추가:
- model_id: nvidia-zai-glm5
model_name: z-ai/glm5
api_base: https://integrate.api.nvidia.com/v1
api_key_name: nvidia
파일 위치: ~/.config/io.datasette.llm/extra-openai-models.yaml
모델 목록 및 정보
# 사용 가능한 모델 목록
llm models
# 별칭 목록
llm aliases
# 모델 옵션 확인
llm models --options -m MODEL_ID
로깅 및 기록
# 최근 로그 확인
llm logs -n 5
# SQLite 로깅 활성화/비활성화
llm logs on
llm logs off
자주 사용하는 명령어 요약
| 명령어 | 설명 |
|---|---|
llm "prompt" |
프롬프트 실행 |
llm -m model "prompt" |
특정 모델 사용 |
llm -t template |
템플릿 사용 |
llm -s "system prompt" |
시스템 프롬프트 |
llm -f file.txt |
프래그먼트 포함 |
llm -a image.jpg |
첨부 파일 |
llm --schema 'name,bio' |
구조화된 출력 |
llm -c |
대화 계속 |
llm chat |
대화 모드 |
llm models |
모델 목록 |
llm templates |
템플릿 목록 |
llm keys |
키 관리 |
참고 리소스
- 공식 문서: https://llm.datasette.io/
- GitHub: https://github.com/simonw/llm
- 플러그인 목록: https://llm.datasette.io/en/stable/plugins/