Skip to content

Commit 5d237ce

Browse files
committed
Show options in Markdown logs output, closes #1322
1 parent 4766f47 commit 5d237ce

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

llm/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,15 @@ def _display_fragments(fragments, title):
20832083
should_show_conversation = False
20842084
click.echo("## Prompt\n\n{}".format(row["prompt"] or "-- none --"))
20852085
_display_fragments(row["prompt_fragments"], "Prompt fragments")
2086+
if row["options_json"]:
2087+
options = row["options_json"]
2088+
if isinstance(options, str):
2089+
options = json.loads(options)
2090+
if options:
2091+
options_text = "\n".join(
2092+
"- {}: {}".format(key, value) for key, value in options.items()
2093+
)
2094+
click.echo("\n## Options\n\n{}".format(options_text))
20862095
if row["system"] != current_system:
20872096
if row["system"] is not None:
20882097
click.echo("\n## System\n\n{}".format(row["system"]))

tests/test_llm_logs.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,42 @@ def test_logs_text(log_path, usage):
136136
assert output == expected
137137

138138

139+
def test_logs_text_with_options(user_path):
140+
"""Test that ## Options section appears when options_json is set"""
141+
log_path = str(user_path / "logs_with_options.db")
142+
db = sqlite_utils.Database(log_path)
143+
migrate(db)
144+
start = datetime.datetime.now(datetime.timezone.utc)
145+
146+
# Create response with options
147+
db["responses"].insert(
148+
{
149+
"id": str(monotonic_ulid()).lower(),
150+
"system": "system",
151+
"prompt": "prompt",
152+
"response": "response",
153+
"model": "davinci",
154+
"datetime_utc": start.isoformat(),
155+
"conversation_id": "abc123",
156+
"input_tokens": 2,
157+
"output_tokens": 5,
158+
"options_json": json.dumps(
159+
{"thinking_level": "high", "media_resolution": "low"}
160+
),
161+
}
162+
)
163+
164+
runner = CliRunner()
165+
result = runner.invoke(cli, ["logs", "-p", str(log_path)], catch_exceptions=False)
166+
assert result.exit_code == 0
167+
output = result.output
168+
169+
# Verify ## Options section is present
170+
assert "## Options\n\n" in output
171+
assert "- thinking_level: high" in output
172+
assert "- media_resolution: low" in output
173+
174+
139175
@pytest.mark.parametrize("n", (None, 0, 2))
140176
def test_logs_json(n, log_path):
141177
"Test that logs command correctly returns requested -n records"

0 commit comments

Comments
 (0)