Skip to content

Commit

Permalink
Fix for llm logs -q plus -m bug, closes #515
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 16, 2024
1 parent 68df972 commit 964f4d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion llm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ def logs_list(
if conversation_id:
where_bits.append("responses.conversation_id = :conversation_id")
if where_bits:
sql_format["extra_where"] = " where " + " and ".join(where_bits)
where_ = " and " if query else " where "
sql_format["extra_where"] = where_ + " and ".join(where_bits)

final_sql = sql.format(**sql_format)
rows = list(
Expand Down
15 changes: 9 additions & 6 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,19 @@ def test_logs_filtered(user_path, model):


@pytest.mark.parametrize(
"query,expected",
"query,extra_args,expected",
(
# With no search term order should be by datetime
("", ["doc1", "doc2", "doc3"]),
("", [], ["doc1", "doc2", "doc3"]),
# With a search it's order by rank instead
("llama", ["doc1", "doc3"]),
("alpaca", ["doc2"]),
("llama", [], ["doc1", "doc3"]),
("alpaca", [], ["doc2"]),
# Model filter should work too
("llama", ["-m", "davinci"], ["doc1", "doc3"]),
("llama", ["-m", "davinci2"], []),
),
)
def test_logs_search(user_path, query, expected):
def test_logs_search(user_path, query, extra_args, expected):
log_path = str(user_path / "logs.db")
db = sqlite_utils.Database(log_path)
migrate(db)
Expand All @@ -175,7 +178,7 @@ def _insert(id, text):
_insert("doc2", "alpaca")
_insert("doc3", "llama llama")
runner = CliRunner()
result = runner.invoke(cli, ["logs", "list", "-q", query, "--json"])
result = runner.invoke(cli, ["logs", "list", "-q", query, "--json"] + extra_args)
assert result.exit_code == 0
records = json.loads(result.output.strip())
assert [record["id"] for record in records] == expected
Expand Down

0 comments on commit 964f4d9

Please sign in to comment.