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

Support multiple stop options for OpenAI models #89

Open
simonw opened this issue Jul 10, 2023 · 2 comments
Open

Support multiple stop options for OpenAI models #89

simonw opened this issue Jul 10, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jul 10, 2023

stop: Optional[str] = Field(
description=("A string where the API will stop generating further tokens."),
default=None,
)

Ideally this would duplicate the official docs:

Up to 4 sequences where the API will stop generating further tokens.

@simonw simonw added the enhancement New feature or request label Jul 10, 2023
@simonw
Copy link
Owner Author

simonw commented Jul 10, 2023

The trick here is figuring out the syntax, since options can only be specified once as a string. I'll probably do a trick a bit like what I did with logit_bias:

@field_validator("logit_bias")
def validate_logit_bias(cls, logit_bias):
if logit_bias is None:
return None
if isinstance(logit_bias, str):
try:
logit_bias = json.loads(logit_bias)
except json.JSONDecodeError:
raise ValueError("Invalid JSON in logit_bias string")
validated_logit_bias = {}
for key, value in logit_bias.items():
try:
int_key = int(key)
int_value = int(value)
if -100 <= int_value <= 100:
validated_logit_bias[int_key] = int_value
else:
raise ValueError("Value must be between -100 and 100")
except ValueError:
raise ValueError("Invalid key-value pair in logit_bias dictionary")
return validated_logit_bias

@simonw
Copy link
Owner Author

simonw commented Jul 16, 2023

Here's how Replicate partially solved this: https://replicate.com/joehoover/falcon-40b-instruct

Comma delimited string specifying stop sequences. Multi-token stop sequences are supported, but they cannot contain commas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant