From 6114bfd221355b605afe3aaa240e5cce699a4e5a Mon Sep 17 00:00:00 2001 From: kingbri Date: Sun, 28 Apr 2024 12:46:28 -0400 Subject: [PATCH] API: Fix banned_tokens string when empty The string should not be parsed and any non-string elements should be removed as well. Signed-off-by: kingbri --- common/sampling.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/common/sampling.py b/common/sampling.py index c782042..6c22bfd 100644 --- a/common/sampling.py +++ b/common/sampling.py @@ -249,11 +249,14 @@ class BaseSamplerRequest(BaseModel): self.validate_params() # Convert stop to an array of strings - if isinstance(self.stop, str): + if self.stop and isinstance(self.stop, str): self.stop = [self.stop] - if isinstance(self.banned_tokens, str): - self.banned_tokens = list(map(int, self.banned_tokens.split(","))) + # Convert string banned tokens to an integer list + if self.banned_tokens and isinstance(self.banned_tokens, str): + self.banned_tokens = [ + int(x) for x in self.banned_tokens.split(",") if x.isdigit() + ] gen_params = { "max_tokens": self.max_tokens,