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

[Bug fix]: CLI overwriting an app does not update configuration #1863

Closed
1 change: 0 additions & 1 deletion agenta-backend/agenta_backend/models/api/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class SaveConfigPayload(BaseModel):
base_id: str
config_name: str
parameters: Dict[str, Any]
overwrite: bool
aybruhm marked this conversation as resolved.
Show resolved Hide resolved


class VariantActionEnum(str, Enum):
Expand Down
11 changes: 6 additions & 5 deletions agenta-backend/agenta_backend/routers/configs_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ async def save_config(
break

if variant_to_overwrite is not None:
if payload.overwrite or variant_to_overwrite.config_parameters == {}:
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
print(f"update_variant_parameters ===> {payload.overwrite}")
if variant_to_overwrite.config_parameters == {}: # type: ignore
logger.info(
f"Updating variant {str(variant_to_overwrite.id)} parameters with {payload.parameters}"
)
await app_manager.update_variant_parameters(
app_variant_id=str(variant_to_overwrite.id),
parameters=payload.parameters,
Expand All @@ -73,10 +75,9 @@ async def save_config(
status_code=400,
detail="Config name already exists. Please use a different name or set overwrite to True.",
)

else:
print(
f"add_variant_from_base_and_config overwrite ===> {payload.overwrite}"
)
logger.info("Adding variant from base and config")
await db_manager.add_variant_from_base_and_config(
base_db=base_db,
new_config_name=payload.config_name,
Expand Down
5 changes: 4 additions & 1 deletion agenta-backend/agenta_backend/services/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,10 @@ async def update_variant_parameters(
raise NoResultFound(f"App variant with id {app_variant_id} not found")

# Update associated ConfigDB parameters
app_variant_db.config_parameters.update(parameters)
if parameters == {}:
app_variant_db.config_parameters = {}
else:
app_variant_db.config_parameters.update(parameters)

# ...and variant versioning
app_variant_db.revision += 1 # type: ignore
Expand Down
7 changes: 0 additions & 7 deletions agenta-cli/agenta/cli/variant_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,6 @@ def serve_cli(ctx, app_folder: str, file_name: str, overwrite: bool):
click.echo(click.style(f"Error message: {str(e)}", fg="red"))
return

try:
api_key = helper.get_global_config("api_key")
except Exception as e:
click.echo(click.style("Failed to retrieve the api key.", fg="red"))
click.echo(click.style(f"Error message: {str(e)}", fg="red"))
return

try:
variant_id = add_variant(
app_folder=app_folder, file_name=file_name, host=host, overwrite=overwrite
Expand Down
7 changes: 2 additions & 5 deletions agenta-cli/agenta/client/api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import os
import toml
import time
import click
from typing import Dict
from pathlib import Path
from agenta.client.backend import client
from agenta.client.api_models import Image
from requests.exceptions import RequestException

from agenta.client.api_models import Image
from agenta.client.backend.client import AgentaApi
from agenta.client.exceptions import APIRequestError

Expand Down
9 changes: 0 additions & 9 deletions agenta-cli/agenta/client/backend/resources/configs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def save_config(
base_id: str,
config_name: str,
parameters: typing.Dict[str, typing.Any],
overwrite: bool,
) -> typing.Any:
"""
Parameters:
Expand All @@ -88,8 +87,6 @@ def save_config(
- config_name: str.

- parameters: typing.Dict[str, typing.Any].

- overwrite: bool.
---
from agenta.client import AgentaApi

Expand All @@ -101,7 +98,6 @@ def save_config(
base_id="base_id",
config_name="config_name",
parameters={},
overwrite=True,
)
"""
_response = self._client_wrapper.httpx_client.request(
Expand All @@ -112,7 +108,6 @@ def save_config(
"base_id": base_id,
"config_name": config_name,
"parameters": parameters,
"overwrite": overwrite,
}
),
headers=self._client_wrapper.get_headers(),
Expand Down Expand Up @@ -255,7 +250,6 @@ async def save_config(
base_id: str,
config_name: str,
parameters: typing.Dict[str, typing.Any],
overwrite: bool,
) -> typing.Any:
"""
Parameters:
Expand All @@ -264,8 +258,6 @@ async def save_config(
- config_name: str.

- parameters: typing.Dict[str, typing.Any].

- overwrite: bool.
---
from agenta.client import AsyncAgentaApi

Expand All @@ -288,7 +280,6 @@ async def save_config(
"base_id": base_id,
"config_name": config_name,
"parameters": parameters,
"overwrite": overwrite,
}
),
headers=self._client_wrapper.get_headers(),
Expand Down
18 changes: 9 additions & 9 deletions agenta-cli/agenta/sdk/agenta_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,43 +103,43 @@ def __init__(self, base_id: str, host: str, api_key: str = ""):
self.persist = False
else:
self.persist = True
self.client = AgentaApi(base_url=self.host + "/api", api_key=api_key)
self.client = AgentaApi(
base_url=self.host + "/api", api_key="" if not api_key else api_key
)

def register_default(self, overwrite=False, **kwargs):
def register_default(self, **kwargs):
"""alias for default"""
return self.default(overwrite=overwrite, **kwargs)
return self.default(**kwargs)

def default(self, overwrite=False, **kwargs):
def default(self, **kwargs):
"""Saves the default parameters to the app_name and base_name in case they are not already saved.
Args:
overwrite: Whether to overwrite the existing configuration or not
**kwargs: A dict containing the parameters
"""
self.set(
**kwargs
) # In case there is no connectivity, we still can use the default values
try:
self.push(config_name="default", overwrite=overwrite, **kwargs)
self.push(config_name="default", **kwargs)
except Exception as ex:
logger.warning(
"Unable to push the default configuration to the server. %s", str(ex)
)

def push(self, config_name: str, overwrite=True, **kwargs):
def push(self, config_name: str, **kwargs):
"""Pushes the parameters for the app variant to the server
Args:
config_name: Name of the configuration to push to
overwrite: Whether to overwrite the existing configuration or not
**kwargs: A dict containing the parameters
"""

if not self.persist:
return
try:
self.client.configs.save_config(
base_id=self.base_id,
config_name=config_name,
parameters=kwargs,
overwrite=overwrite,
)
except Exception as ex:
logger.warning(
Expand Down
Loading