Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENG-879 ENG-882 Move cli logic into its own folder #198

Merged
merged 9 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
kxtran marked this conversation as resolved.
Show resolved Hide resolved
run: poetry run pytest -vv tests/test_cli.py
65 changes: 1 addition & 64 deletions log10/__main__.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,5 @@
import click
from log10.cli.cli_commands import cli

from log10.completions.completions import benchmark_models, download_completions, get_completion, list_completions
from log10.feedback.autofeedback import auto_feedback_icl, get_autofeedback_cli
from log10.feedback.feedback import create_feedback, download_feedback, get_feedback, list_feedback
from log10.feedback.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()
47 changes: 47 additions & 0 deletions log10/cli/autofeedback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json

import click
import rich
from rich.console import Console

from log10.feedback.autofeedback import AutoFeedbackICL, get_autofeedback


@click.command()
@click.option("--task_id", help="Feedback task ID")
@click.option("--content", help="Completion content")
@click.option("--file", "-f", help="File containing completion content")
@click.option("--completion_id", help="Completion ID")
@click.option("--num_samples", default=5, help="Number of samples to use for few-shot learning")
def auto_feedback_icl(task_id: str, content: str, file: str, completion_id: str, num_samples: int):
"""
Generate feedback with existing human feedback based on in context learning
"""
options_count = sum([1 for option in [content, file, completion_id] if option])
if options_count > 1:
click.echo("Only one of --content, --file, or --completion_id should be provided.")
return

console = Console()
auto_feedback_icl = AutoFeedbackICL(task_id, num_samples=num_samples)
if completion_id:
results = auto_feedback_icl.predict(completion_id=completion_id)
console.print_json(results)
return

if file:
with open(file, "r") as f:
content = f.read()
results = auto_feedback_icl.predict(text=content)
console.print_json(results)


@click.command()
@click.option("--completion-id", required=True, help="Completion ID")
def get_autofeedback_cli(completion_id: str):
"""
Get an auto feedback by completion id
"""
res = get_autofeedback(completion_id)
if res:
rich.print_json(json.dumps(res["data"], indent=4))
71 changes: 71 additions & 0 deletions log10/cli/cli_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
try:
import click
kxtran marked this conversation as resolved.
Show resolved Hide resolved
except ImportError:
print(
kxtran marked this conversation as resolved.
Show resolved Hide resolved
"To use log10 cli you must install optional modules. Please install them with `pip install 'log10-io[cli]'`."
)
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")
Loading
Loading