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

Optional interactive mode #1621

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 13 additions & 6 deletions agenta-cli/agenta/cli/variant_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def variant():


def add_variant(
app_folder: str, file_name: str, host: str, config_name="default"
app_folder: str, file_name: str, host: str, overwrite: bool, config_name="default"
) -> str:
"""
Adds a variant to the backend. Sends the code as a tar to the backend, which then containerizes it and adds it to the backend store.
Expand Down Expand Up @@ -97,14 +97,13 @@ def add_variant(

# update the config file with the variant names from the backend
variant_name = f"{base_name}.{config_name}"
overwrite = False

client = AgentaApi(
base_url=f"{host}/{BACKEND_URL_SUFFIX}",
api_key=api_key,
)

if variant_name in config["variants"]:
if variant_name in config["variants"] and not overwrite:
aakrem marked this conversation as resolved.
Show resolved Hide resolved
overwrite = questionary.confirm(
"This variant already exists. Do you want to overwrite it?"
).ask()
Expand Down Expand Up @@ -443,9 +442,15 @@ def remove_variant_cli(variant_name: str, app_folder: str):
)
@click.option("--app_folder", default=".")
@click.option("--file_name", default=None, help="The name of the file to run")
@click.option(
"--overwrite",
is_flag=True,
default=False,
help="Overwrite the existing variant if it exists",
)
@click.pass_context
def serve_cli(ctx, app_folder: str, file_name: str):
"""Adds a variant to the web ui and serves the API locally."""
def serve_cli(ctx, app_folder: str, file_name: str, overwrite: bool):
"""Adds a variant to the web UI and serves the API locally."""

if not file_name:
if ctx.args:
Expand Down Expand Up @@ -480,7 +485,9 @@ def serve_cli(ctx, app_folder: str, file_name: str):
return

try:
variant_id = add_variant(app_folder=app_folder, file_name=file_name, host=host)
variant_id = add_variant(
app_folder=app_folder, file_name=file_name, host=host, overwrite=overwrite
)
except Exception as e:
click.echo(click.style("Failed to add variant.", fg="red"))
click.echo(click.style(f"Error message: {str(e)}", fg="red"))
Expand Down
9 changes: 8 additions & 1 deletion docs/developer_guides/cli/quick-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ def translate(sentence:str, language:str):
## Serve the application

```bash
agenta variant serve myapp.py
agenta variant serve --file_name myapp.py
aakrem marked this conversation as resolved.
Show resolved Hide resolved
```

This command deploys a new variant to the Agenta platform. It processes the code in the specified folder, with `myapp.py` as the entrypoint. This command builds a Docker image and deploys a container based on it. As a result, the variant becomes accessible in the web UI, allowing for prediction generation and API calls. The variant is named as `myapp.default` in the UI.


## Overwrite an application

```bash
agenta variant serve --file_name myapp.py --overwrite
```
Loading