Add support for OpenAI API o1 model (#3363)

Co-authored-by: Shan Yu <shanyu1@g.ucla.edu>
This commit is contained in:
Chuyue Sun
2025-02-13 19:43:00 -08:00
committed by GitHub
parent 31eec35ba8
commit 6cc309557a
3 changed files with 63 additions and 0 deletions

View File

@@ -161,6 +161,10 @@ class OpenAI(BaseBackend):
prompt = s.text_
kwargs = sampling_params.to_openai_kwargs()
if self.model_name.startswith("o1") or self.model_name.startswith("o3"):
kwargs.pop("max_tokens", None)
else:
kwargs.pop("max_completion_tokens", None)
comp = openai_completion(
client=self.client,
token_usage=self.token_usage,
@@ -175,6 +179,7 @@ class OpenAI(BaseBackend):
), "constrained type not supported on chat model"
kwargs = sampling_params.to_openai_kwargs()
kwargs.pop("stop")
comp = openai_completion(
client=self.client,
token_usage=self.token_usage,

View File

@@ -63,6 +63,7 @@ class SglSamplingParams:
warnings.warn("Regular expression is not supported in the OpenAI backend.")
return {
"max_tokens": self.max_new_tokens,
"max_completion_tokens": self.max_new_tokens,
"stop": self.stop or None,
"temperature": self.temperature,
"top_p": self.top_p,