Skip to content

Commit

Permalink
Merge pull request #574 from Agenta-AI/improve_error_message_cli
Browse files Browse the repository at this point in the history
Improved error messaging in both start_variant and in the client
  • Loading branch information
mmabrouk authored Sep 10, 2023
2 parents 334411c + ddd9a1c commit 5e2e50b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
41 changes: 28 additions & 13 deletions agenta-cli/agenta/cli/variant_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,25 +331,40 @@ def serve_cli(app_folder: str, file_name: str):

try:
config_check(app_folder)
except Exception as e:
click.echo(click.style("Failed during configuration check.", fg="red"))
click.echo(click.style(f"Error message: {str(e)}", fg="red"))
return

try:
host = get_host(app_folder)
except Exception as e:
click.echo(click.style("Failed to retrieve the host.", fg="red"))
click.echo(click.style(f"Error message: {str(e)}", fg="red"))
return

try:
variant_name = add_variant(
app_folder=app_folder, file_name=file_name, host=host
)
if (
variant_name
): # otherwise we either failed or we were doing an update and we don't need to manually start the variant!!
start_variant(variant_name=variant_name, app_folder=app_folder, host=host)
except ConnectionError:
error_msg = (
"Failed to connect to Agenta backend. Here's how you can solve the issue:\n"
)
error_msg += "- First, please ensure that the backend service is running and accessible.\n"
error_msg += (
"- Second, try restarting the containers (if using Docker Compose)."
)
click.echo(click.style(f"{error_msg}", fg="red"))
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"))
return

if variant_name:
try:
start_variant(variant_name=variant_name, app_folder=app_folder, host=host)
except ConnectionError:
error_msg = "Failed to connect to Agenta backend. Here's how you can solve the issue:\n"
error_msg += "- First, please ensure that the backend service is running and accessible.\n"
error_msg += (
"- Second, try restarting the containers (if using Docker Compose)."
)
click.echo(click.style(f"{error_msg}", fg="red"))
except Exception as e:
click.echo(click.style("Failed to start container with LLM app.", fg="red"))
click.echo(click.style(f"Error message: {str(e)}", fg="red"))


@variant.command(name="list")
Expand Down
12 changes: 6 additions & 6 deletions agenta-cli/agenta/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def add_variant_to_server(app_name: str, variant_name: str, image: Image, host:
timeout=600,
)
if response.status_code != 200:
error_message = response.json()["detail"]
error_message = response.json()
raise APIRequestError(
f"Request to app_variant endpoint failed with status code {response.status_code} and error message: {error_message}."
)
Expand All @@ -52,7 +52,7 @@ def start_variant(app_name: str, variant_name: str, host: str) -> str:
)

if response.status_code != 200:
error_message = response.json()["detail"]
error_message = response.json()
raise APIRequestError(
f"Request to start variant endpoint failed with status code {response.status_code} and error message: {error_message}."
)
Expand All @@ -75,7 +75,7 @@ def list_variants(app_name: str, host: str) -> List[AppVariant]:

# Check for successful request
if response.status_code != 200:
error_message = response.json()["detail"]
error_message = response.json()
raise APIRequestError(
f"Request to list_variants endpoint failed with status code {response.status_code} and error message: {error_message}."
)
Expand All @@ -101,7 +101,7 @@ def remove_variant(app_name: str, variant_name: str, host: str):

# Check for successful request
if response.status_code != 200:
error_message = response.json()["detail"]
error_message = response.json()
raise APIRequestError(
f"Request to remove_variant endpoint failed with status code {response.status_code} and error message: {error_message}"
)
Expand All @@ -122,7 +122,7 @@ def update_variant_image(app_name: str, variant_name: str, image: Image, host: s
timeout=600,
)
if response.status_code != 200:
error_message = response.json()["detail"]
error_message = response.json()
raise APIRequestError(
f"Request to update app_variant failed with status code {response.status_code} and error message: {error_message}."
)
Expand All @@ -141,7 +141,7 @@ def send_docker_tar(
)

if response.status_code == 500:
response_error = response.json()["detail"]
response_error = response.json()
error_msg = "Serving the variant failed.\n"
error_msg += f"Log: {response_error}\n"
error_msg += "Here's how you may be able to solve the issue:\n"
Expand Down

0 comments on commit 5e2e50b

Please sign in to comment.