diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7956e48..78a1940 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -123,3 +123,6 @@ jobs: echo "This is a schedule event" poetry run pytest -vv tests/ poetry run pytest --openai_model=gpt-4o -m chat -vv tests/test_openai.py + + - name: Test cli commands + run: poetry run pytest -vv tests/test_cli.py \ No newline at end of file diff --git a/log10/__main__.py b/log10/__main__.py index 32409c5..07c9387 100644 --- a/log10/__main__.py +++ b/log10/__main__.py @@ -1,74 +1,5 @@ -try: - import click -except ImportError: - print( - "To use log10 cli you must install optional modules. Please install them with `pip install 'log10-io[cliModules]'`." - ) - exit(1) +from log10.cli.cli_commands import cli -from log10.cli.autofeedback import auto_feedback_icl, get_autofeedback_cli -from log10.cli.completions import benchmark_models, download_completions, get_completion, list_completions -from log10.cli.feedback import create_feedback, download_feedback, get_feedback, list_feedback -from log10.cli.feedback_task import create_feedback_task, get_feedback_task, list_feedback_task - - -@click.group() -def cli(): - pass - - -@click.group() -def completions(): - """ - Manage logs from completions i.e. logs from users - """ - pass - - -@click.group(name="feedback") -def feedback(): - """ - Manage feedback for completions i.e. capturing feedback from users - """ - pass - - -@click.group(name="auto_feedback") -def auto_feedback(): - """ - Manage auto feedback for completions i.e. capturing feedback from users - """ - pass - - -@click.group() -def feedback_task(): - """ - Manage tasks for feedback i.e. instructions and schema for feedback - """ - pass - - -cli.add_command(completions) -completions.add_command(list_completions, "list") -completions.add_command(get_completion, "get") -completions.add_command(download_completions, "download") -completions.add_command(benchmark_models, "benchmark_models") - -cli.add_command(feedback) -feedback.add_command(create_feedback, "create") -feedback.add_command(list_feedback, "list") -feedback.add_command(get_feedback, "get") -feedback.add_command(download_feedback, "download") -feedback.add_command(auto_feedback_icl, "predict") -feedback.add_command(auto_feedback, "autofeedback") -# Subcommands for auto_feedback under feedback command -auto_feedback.add_command(get_autofeedback_cli, "get") - -cli.add_command(feedback_task) -feedback_task.add_command(create_feedback_task, "create") -feedback_task.add_command(list_feedback_task, "list") -feedback_task.add_command(get_feedback_task, "get") if __name__ == "__main__": cli() diff --git a/log10/cli/cli_commands.py b/log10/cli/cli_commands.py new file mode 100644 index 0000000..2aa5685 --- /dev/null +++ b/log10/cli/cli_commands.py @@ -0,0 +1,71 @@ +try: + import click +except ImportError: + print( + "To use log10 cli you must install optional modules. Please install them with `pip install 'log10-io[cliModules]'`." + ) + exit(1) + +from log10.cli.autofeedback import auto_feedback_icl, get_autofeedback_cli +from log10.cli.completions import benchmark_models, download_completions, get_completion, list_completions +from log10.cli.feedback import create_feedback, download_feedback, get_feedback, list_feedback +from log10.cli.feedback_task import create_feedback_task, get_feedback_task, list_feedback_task + + +@click.group() +def cli(): + pass + + +@click.group() +def completions(): + """ + Manage logs from completions i.e. logs from users + """ + pass + + +@click.group(name="feedback") +def feedback(): + """ + Manage feedback for completions i.e. capturing feedback from users + """ + pass + + +@click.group(name="auto_feedback") +def auto_feedback(): + """ + Manage auto feedback for completions i.e. capturing feedback from users + """ + pass + + +@click.group() +def feedback_task(): + """ + Manage tasks for feedback i.e. instructions and schema for feedback + """ + pass + + +cli.add_command(completions) +completions.add_command(list_completions, "list") +completions.add_command(get_completion, "get") +completions.add_command(download_completions, "download") +completions.add_command(benchmark_models, "benchmark_models") + +cli.add_command(feedback) +feedback.add_command(create_feedback, "create") +feedback.add_command(list_feedback, "list") +feedback.add_command(get_feedback, "get") +feedback.add_command(download_feedback, "download") +feedback.add_command(auto_feedback_icl, "predict") +feedback.add_command(auto_feedback, "autofeedback") +# Subcommands for auto_feedback under feedback command +auto_feedback.add_command(get_autofeedback_cli, "get") + +cli.add_command(feedback_task) +feedback_task.add_command(create_feedback_task, "create") +feedback_task.add_command(list_feedback_task, "list") +feedback_task.add_command(get_feedback_task, "get") diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..289054a --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,66 @@ +import pytest +from click.testing import CliRunner + +from log10.cli.cli_commands import cli + + +completion_id = "fb891d4e-f99c-4d8d-a95c-24d2ed7a0807" +feedback_id = "0e43b537-5f0c-4f47-ba83-4938514477c3" +feedback_task_id = "1c84079e-a7bb-47e1-86c7-e32b51045e8e" + + +@pytest.fixture +def runner(): + return CliRunner() + + +def test_list_completions(runner): + result = runner.invoke(cli, ["completions", "list"]) + print(result.output) + assert result.exit_code == 0 + assert "total_completions=" in result.output + + +def test_get_completion(runner): + result = runner.invoke(cli, ["completions", "get", "--id", completion_id]) + assert result.exit_code == 0 + assert completion_id in result.output + + +def test_download_completions(runner): + result = runner.invoke(cli, ["completions", "download", "--limit", "1", "--tags", "log10/summary-grading"]) + assert result.exit_code == 0 + assert "Download total completions: 1/" in result.output + + +def test_list_feedback(runner): + result = runner.invoke(cli, ["feedback", "list"]) + assert result.exit_code == 0 + assert "Total feedback:" in result.output + + +def test_get_feedback(runner): + result = runner.invoke(cli, ["feedback", "get", "--id", feedback_id]) + assert result.exit_code == 0 + assert feedback_id in result.output + + +def test_download_feedback(runner): + result = runner.invoke(cli, ["feedback", "download", "--limit", "1"]) + assert result.exit_code == 0 + + +def test_get_autofeedback(runner): + result = runner.invoke(cli, ["feedback", "autofeedback", "get", "--completion-id", completion_id]) + assert result.exit_code == 0 + assert completion_id in result.output + + +def test_list_feedback_task(runner): + result = runner.invoke(cli, ["feedback-task", "list"]) + assert result.exit_code == 0 + + +def test_get_feedback_task(runner): + result = runner.invoke(cli, ["feedback-task", "get", "--id", feedback_task_id]) + assert result.exit_code == 0