Skip to content

Commit

Permalink
Fix openai protocols and pass top_k, min_p (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
merrymercy authored Dec 17, 2024
1 parent 33c5ff2 commit 361ea8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions python/sglang/srt/openai_api/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ def v1_generate_request(
"stop": request.stop,
"stop_token_ids": request.stop_token_ids,
"top_p": request.top_p,
"top_k": request.top_k,
"min_p": request.min_p,
"presence_penalty": request.presence_penalty,
"frequency_penalty": request.frequency_penalty,
"repetition_penalty": request.repetition_penalty,
Expand Down Expand Up @@ -926,6 +928,8 @@ def v1_chat_generate_request(
"stop": stop,
"stop_token_ids": request.stop_token_ids,
"top_p": request.top_p,
"top_k": request.top_k,
"min_p": request.min_p,
"presence_penalty": request.presence_penalty,
"frequency_penalty": request.frequency_penalty,
"repetition_penalty": request.repetition_penalty,
Expand Down
14 changes: 9 additions & 5 deletions python/sglang/srt/openai_api/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,19 @@ class CompletionRequest(BaseModel):
temperature: float = 1.0
top_p: float = 1.0
user: Optional[str] = None
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None

# Extra parameters for SRT backend only and will be ignored by OpenAI models.
json_schema: Optional[str] = None
regex: Optional[str] = None
top_k: int = -1
min_p: float = 0.0
min_tokens: int = 0
regex: Optional[str] = None
json_schema: Optional[str] = None
repetition_penalty: float = 1.0
stop_token_ids: Optional[List[int]] = None
no_stop_trim: bool = False
ignore_eos: bool = False
skip_special_tokens: bool = True
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None


class CompletionResponseChoice(BaseModel):
Expand Down Expand Up @@ -276,14 +278,16 @@ class ChatCompletionRequest(BaseModel):
user: Optional[str] = None

# Extra parameters for SRT backend only and will be ignored by OpenAI models.
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None
regex: Optional[str] = None
top_k: int = -1
min_p: float = 0.0
min_tokens: int = 0
regex: Optional[str] = None
repetition_penalty: float = 1.0
stop_token_ids: Optional[List[int]] = None
no_stop_trim: bool = False
ignore_eos: bool = False
skip_special_tokens: bool = True
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None


class ChatMessage(BaseModel):
Expand Down

0 comments on commit 361ea8d

Please sign in to comment.