Skip to content

Commit

Permalink
llm logs -xr behaves same as llm logs -x
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 10, 2025
1 parent 5055fc0 commit 8a87d1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,15 +990,16 @@ def logs_list(
for attachment in attachments_by_id.get(row["id"], [])
]
output = json.dumps(list(rows), indent=2)
elif response:
# Just output the last response
if rows:
output = rows[-1]["response"]
elif extract:
# Extract and return first code block
for row in rows:
output = extract_first_fenced_code_block(row["response"])
if output is not None:
break
elif response:
# Just output the last response
if rows:
output = rows[-1]["response"]

if output is not None:
click.echo(output)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,17 @@ def test_logs_response_only(args, log_path):


@pytest.mark.parametrize(
"args", (["-x"], ["--extract"], ["list", "-x"], ["list", "--extract"])
"args",
(
["-x"],
["--extract"],
["list", "-x"],
["list", "--extract"],
# Using -xr together should have same effect as just -x
["-xr"],
["-x", "-r"],
["--extract", "--response"],
),
)
def test_logs_extract_first_code(args, log_path):
"Test that logs -x/--extract returns the first code block"
Expand Down

0 comments on commit 8a87d1a

Please sign in to comment.