记录到SQLite#
llm 默认将所有提示和响应记录到 SQLite 数据库中。
你可以使用llm logs path命令找到该数据库的位置:
llm logs path
在我的Mac上输出:
/Users/simon/Library/Application Support/io.datasette.llm/logs.db
这将在其他操作系统中有所不同。
为了避免记录单个提示,可以向命令传递 --no-log 或 -n:
llm 'Ten names for cheesecakes' -n
默认关闭日志记录:
llm logs off
如果您已关闭日志记录,您仍然可以通过添加 --log 来记录单个提示和响应:
llm 'Five ambitious names for a pet pterodactyl' --log
要再次默认开启日志记录:
llm logs on
要查看日志数据库的状态,请运行以下命令:
llm logs status
示例输出:
Logging is ON for all prompts
Found log database at /Users/simon/Library/Application Support/io.datasette.llm/logs.db
Number of conversations logged: 33
Number of responses logged: 48
Database file size: 19.96MB
查看日志#
您可以使用llm logs命令查看日志:
llm logs
这将输出最近记录的三项内容,以Markdown格式显示,包括提示和响应,并使用Markdown进行格式化。
要仅获取最近的提示响应作为纯文本,请添加 -r/--response:
llm logs -r
使用 -x/--extract 从选定的日志条目中提取并返回第一个围栏代码块:
llm logs --extract
或者 --xl/--extract-last 用于最后一个围栏代码块:
llm logs --extract-last
添加 --json 以获取 JSON 格式的日志消息:
llm logs --json
添加 -n 10 以查看最近的十个项目:
llm logs -n 10
或者 -n 0 查看所有曾经记录的内容:
llm logs -n 0
你可以使用-t/--truncate选项来截断提示和响应的显示。这可以帮助使JSON输出更易读:
llm logs -n 1 -t --json
示例输出:
[
{
"id": "01jm8ec74wxsdatyn5pq1fp0s5",
"model": "anthropic/claude-3-haiku-20240307",
"prompt": "hi",
"system": null,
"prompt_json": null,
"response": "Hello! How can I assist you today?",
"conversation_id": "01jm8ec74taftdgj2t4zra9z0j",
"duration_ms": 560,
"datetime_utc": "2025-02-16T22:34:30.374882+00:00",
"input_tokens": 8,
"output_tokens": 12,
"token_details": null,
"conversation_name": "hi",
"conversation_model": "anthropic/claude-3-haiku-20240307",
"attachments": []
}
]
-s/–short 模式#
使用 -s/--short 查看缩短的 YAML 日志,其中包含截断的提示且没有响应:
llm logs -n 2 --short
示例输出:
- model: deepseek-reasoner
datetime: '2025-02-02T06:39:53'
conversation: 01jk2pk05xq3d0vgk0202zrsg1
prompt: H01 There are five huts. H02 The Scotsman lives in the purple hut. H03 The Welshman owns the parrot. H04 Kombucha is...
- model: o3-mini
datetime: '2025-02-02T19:03:05'
conversation: 01jk40qkxetedzpf1zd8k9bgww
system: Formatting re-enabled. Write a detailed README with extensive usage examples.
prompt: <documents> <document index="1"> <source>./Cargo.toml</source> <document_content> [package] name = "py-limbo" version...
包含 -u/--usage 以包含令牌使用信息:
llm logs -n 1 --short --usage
示例输出:
- model: o3-mini
datetime: '2025-02-16T23:00:56'
conversation: 01jm8fxxnef92n1663c6ays8xt
system: Produce Python code that demonstrates every possible usage of yaml.dump
with all of the arguments it can take, especi...
prompt: <documents> <document index="1"> <source>./setup.py</source> <document_content>
NAME = 'PyYAML' VERSION = '7.0.0.dev0...
usage:
input: 74793
output: 3550
details:
completion_tokens_details:
reasoning_tokens: 2240
对话日志#
要查看您与模型最近的对话的日志,请使用-c:
llm logs -c
要根据对话ID查看特定对话的日志,请使用 --cid ID 或 --conversation ID:
llm logs --cid 01h82n0q9crqtnzmf13gkyxawg
搜索日志#
您可以在prompt或response列中搜索日志中的搜索词。
llm logs -q 'cheesecake'
最相关的术语将显示在输出的底部。
按模型过滤#
你可以使用-m/--model来过滤特定模型(或模型别名)的日志:
llm logs -m chatgpt
使用Datasette浏览日志#
你也可以使用Datasette来浏览你的日志,如下所示:
datasette "$(llm logs path)"
SQL 模式#
以下是logs.db数据库使用的SQL模式:
CREATE TABLE [conversations] (
[id] TEXT PRIMARY KEY,
[name] TEXT,
[model] TEXT
);
CREATE TABLE [responses] (
[id] TEXT PRIMARY KEY,
[model] TEXT,
[prompt] TEXT,
[system] TEXT,
[prompt_json] TEXT,
[options_json] TEXT,
[response] TEXT,
[response_json] TEXT,
[conversation_id] TEXT REFERENCES [conversations]([id]),
[duration_ms] INTEGER,
[datetime_utc] TEXT,
[input_tokens] INTEGER,
[output_tokens] INTEGER,
[token_details] TEXT
);
CREATE VIRTUAL TABLE [responses_fts] USING FTS5 (
[prompt],
[response],
content=[responses]
);
CREATE TABLE [attachments] (
[id] TEXT PRIMARY KEY,
[type] TEXT,
[path] TEXT,
[url] TEXT,
[content] BLOB
);
CREATE TABLE [prompt_attachments] (
[response_id] TEXT REFERENCES [responses]([id]),
[attachment_id] TEXT REFERENCES [attachments]([id]),
[order] INTEGER,
PRIMARY KEY ([response_id],
[attachment_id])
);
responses_fts 配置了针对 responses 表中的 prompt 和 response 列的 SQLite 全文搜索。