Skip to content

Commit

Permalink
Deduplicate choices
Browse files Browse the repository at this point in the history
Ensure choices are not duplicated, as that makes StrEnum impossible to
resolve. Each element should only exist once.
  • Loading branch information
tempusfrangit committed Oct 15, 2024
1 parent 37c141e commit c149092
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python/cog/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ def get_input_create_model_kwargs(signature: inspect.Signature) -> Dict[str, Any
# passed automatically as 'enum' in the schema
if choices:
if InputType == str and isinstance(choices, Iterable): # noqa: E721
# Deduplicate choices
choices = list(set(choices))

class StringEnum(str, enum.Enum):
pass
Expand Down
2 changes: 1 addition & 1 deletion python/tests/server/fixtures/input_choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


class Predictor(BasePredictor):
def predict(self, text: str = Input(choices=["foo", "bar"])) -> str:
def predict(self, text: str = Input(choices=["foo", "bar", "foo"])) -> str:
assert type(text) == str
return text

0 comments on commit c149092

Please sign in to comment.