Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aakrem committed Apr 2, 2024
1 parent 217756e commit 5cc7ea8
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions agenta-cli/agenta/sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def __new__(cls, default: str = None, choices: Dict[str, List[str]] = None):
if choices is None:
choices = {}

# Check if default is in the choices
if default and not any(default in choices for choices in choices.values()):
if not choices:
print(
Expand All @@ -149,30 +148,25 @@ def __new__(cls, default: str = None, choices: Dict[str, List[str]] = None):
default = choices[0]
break

if default is None:
raise ValueError(
"No choices available in the provided choices or default not set"
)

instance = super().__new__(cls, default)
instance.choices = choices
instance.default = default
return instance

def validate(self, value):
if not any(value in group for group in self.options.values()):
if not any(value in group for group in self.choices.values()):
raise ValueError(
f"{value} is not a valid choice. Available choices are: {self.options}"
f"{value} is not a valid choice. Available choices are: {self.choices}"
)

@classmethod
def __modify_schema__(cls, field_schema: dict[str, Any], **kwargs):
options = kwargs.get("options", {})
choices = kwargs.get("choices", {})
field_schema.update(
{
"x-parameter": "grouped_choice",
"type": "string",
"choices": options,
"choices": choices,
}
)

Expand Down

0 comments on commit 5cc7ea8

Please sign in to comment.