diff --git a/docs/help.md b/docs/help.md index e40fc57..eafe8ad 100644 --- a/docs/help.md +++ b/docs/help.md @@ -146,8 +146,9 @@ Options: --help Show this message and exit. Commands: - list* Show recent logged prompts and their responses - path Output the path to the logs.db file + list* Show recent logged prompts and their responses + path Output the path to the logs.db file + status Show current status of database logging ``` #### llm logs path --help ``` @@ -155,6 +156,15 @@ Usage: llm logs path [OPTIONS] Output the path to the logs.db file +Options: + --help Show this message and exit. +``` +#### llm logs status --help +``` +Usage: llm logs status [OPTIONS] + + Show current status of database logging + Options: --help Show this message and exit. ``` diff --git a/llm/cli.py b/llm/cli.py index 3423027..f0500ae 100644 --- a/llm/cli.py +++ b/llm/cli.py @@ -351,6 +351,23 @@ def logs_path(): click.echo(logs_db_path()) +@logs.command(name="status") +def logs_status(): + "Show current status of database logging" + path = logs_db_path() + if not path.exists(): + click.echo("No log database found at {}".format(path)) + return + db = sqlite_utils.Database(path) + migrate(db) + click.echo("Found log database at {}".format(path)) + click.echo("Number of conversations logged:\t{}".format(db["conversations"].count)) + click.echo("Number of responses logged:\t{}".format(db["responses"].count)) + click.echo( + "Database file size: \t\t{}".format(_human_readable_size(path.stat().st_size)) + ) + + @logs.command(name="list") @click.option( "-n", @@ -656,3 +673,17 @@ def render_errors(errors): pm.hook.register_commands(cli=cli) + + +def _human_readable_size(size_bytes): + if size_bytes == 0: + return "0B" + + size_name = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB") + i = 0 + + while size_bytes >= 1024 and i < len(size_name) - 1: + size_bytes /= 1024.0 + i += 1 + + return "{:.2f}{}".format(size_bytes, size_name[i])