Skip to content

Commit c149092

Browse files
committed
Deduplicate choices
Ensure choices are not duplicated, as that makes StrEnum impossible to resolve. Each element should only exist once.
1 parent 37c141e commit c149092

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

python/cog/predictor.py

+2
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ def get_input_create_model_kwargs(signature: inspect.Signature) -> Dict[str, Any
355355
# passed automatically as 'enum' in the schema
356356
if choices:
357357
if InputType == str and isinstance(choices, Iterable): # noqa: E721
358+
# Deduplicate choices
359+
choices = list(set(choices))
358360

359361
class StringEnum(str, enum.Enum):
360362
pass

python/tests/server/fixtures/input_choices.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33

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

0 commit comments

Comments
 (0)