From 7e7ccdc19a510afa40fa4f7195ccbefa1752b63d Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 28 Mar 2025 00:10:58 -0700 Subject: [PATCH] Hide -p/--path in favor of standard -d/--database, closes #857 Spotted while working on #853 --- docs/help.md | 14 +++++++------- llm/cli.py | 32 ++++++++++++++++++++++++++++++-- tests/test_llm_logs.py | 11 +++++++++-- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/docs/help.md b/docs/help.md index ae5aedb..7d6c860 100644 --- a/docs/help.md +++ b/docs/help.md @@ -300,7 +300,7 @@ Usage: llm logs list [OPTIONS] Options: -n, --count INTEGER Number of entries to show - defaults to 3, use 0 for all - -p, --path FILE Path to log database + -d, --database FILE Path to log database -m, --model TEXT Filter by model or model alias -q, --query TEXT Search for logs matching this string --schema TEXT JSON schema, filepath or ID @@ -542,10 +542,10 @@ Usage: llm schemas list [OPTIONS] List stored schemas Options: - -p, --path FILE Path to log database - -q, --query TEXT Search for schemas matching this string - --full Output full schema contents - --help Show this message and exit. + -d, --database FILE Path to log database + -q, --query TEXT Search for schemas matching this string + --full Output full schema contents + --help Show this message and exit. ``` (help-schemas-show)= @@ -556,8 +556,8 @@ Usage: llm schemas show [OPTIONS] SCHEMA_ID Show a stored schema Options: - -p, --path FILE Path to log database - --help Show this message and exit. + -d, --database FILE Path to log database + --help Show this message and exit. ``` (help-schemas-dsl)= diff --git a/llm/cli.py b/llm/cli.py index cfc88c9..58312d3 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -981,6 +981,13 @@ order by prompt_attachments."order" "--path", type=click.Path(readable=True, exists=True, dir_okay=False), help="Path to log database", + hidden=True, +) +@click.option( + "-d", + "--database", + type=click.Path(readable=True, exists=True, dir_okay=False), + help="Path to log database", ) @click.option("-m", "--model", help="Filter by model or model alias") @click.option("-q", "--query", help="Search for logs matching this string") @@ -1036,6 +1043,7 @@ order by prompt_attachments."order" def logs_list( count, path, + database, model, query, schema_input, @@ -1057,6 +1065,8 @@ def logs_list( json_output, ): "Show recent logged prompts and their responses" + if database and not path: + path = database path = pathlib.Path(path or logs_db_path()) if not path.exists(): raise click.ClickException("No log database found at {}".format(path)) @@ -1562,6 +1572,13 @@ def schemas(): "--path", type=click.Path(readable=True, exists=True, dir_okay=False), help="Path to log database", + hidden=True, +) +@click.option( + "-d", + "--database", + type=click.Path(readable=True, exists=True, dir_okay=False), + help="Path to log database", ) @click.option( "queries", @@ -1571,8 +1588,10 @@ def schemas(): help="Search for schemas matching this string", ) @click.option("--full", is_flag=True, help="Output full schema contents") -def schemas_list(path, queries, full): +def schemas_list(path, database, queries, full): "List stored schemas" + if database and not path: + path = database path = pathlib.Path(path or logs_db_path()) if not path.exists(): raise click.ClickException("No log database found at {}".format(path)) @@ -1633,9 +1652,18 @@ def schemas_list(path, queries, full): "--path", type=click.Path(readable=True, exists=True, dir_okay=False), help="Path to log database", + hidden=True, ) -def schemas_show(schema_id, path): +@click.option( + "-d", + "--database", + type=click.Path(readable=True, exists=True, dir_okay=False), + help="Path to log database", +) +def schemas_show(schema_id, path, database): "Show a stored schema" + if database and not path: + path = database path = pathlib.Path(path or logs_db_path()) if not path.exists(): raise click.ClickException("No log database found at {}".format(path)) diff --git a/tests/test_llm_logs.py b/tests/test_llm_logs.py index 98b0e85..2ad2b3b 100644 --- a/tests/test_llm_logs.py +++ b/tests/test_llm_logs.py @@ -250,8 +250,11 @@ def test_logs_path(monkeypatch, env, user_path): @pytest.mark.parametrize("model", ("davinci", "curie")) -def test_logs_filtered(user_path, model): +@pytest.mark.parametrize("path_option", (None, "-p", "--path", "-d", "--database")) +def test_logs_filtered(user_path, model, path_option): log_path = str(user_path / "logs.db") + if path_option: + log_path = str(user_path / "logs_alternative.db") db = sqlite_utils.Database(log_path) migrate(db) db["responses"].insert_all( @@ -265,7 +268,11 @@ def test_logs_filtered(user_path, model): for i in range(100) ) runner = CliRunner() - result = runner.invoke(cli, ["logs", "list", "-m", model, "--json"]) + result = runner.invoke( + cli, + ["logs", "list", "-m", model, "--json"] + + ([path_option, log_path] if path_option else []), + ) assert result.exit_code == 0 records = json.loads(result.output.strip()) assert all(record["model"] == model for record in records)