Skip to content

Commit

Permalink
Support models with non-standard finish_reason (#2229)
Browse files Browse the repository at this point in the history
Some model launchers (TGI, sglang) may return
non-standard `finish_reason` values, such as
`"eos_token"` or `""`. This commit removes the
strict parsing of `finish_reason` so that the
OpenAI-compatible endpoint does not fail for these
model launchers.
  • Loading branch information
jvstme authored Jan 27, 2025
1 parent b30d047 commit 3918689
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/dstack/_internal/proxy/lib/schemas/model_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from dstack._internal.core.models.common import CoreModel

FinishReason = Literal["stop", "length", "tool_calls", "eos_token"]


class ChatMessage(CoreModel):
role: str # TODO(egor-s) types
Expand All @@ -30,15 +28,15 @@ class ChatCompletionsRequest(CoreModel):


class ChatCompletionsChoice(CoreModel):
finish_reason: FinishReason
finish_reason: str
index: int
message: ChatMessage


class ChatCompletionsChunkChoice(CoreModel):
delta: object
logprobs: object = {}
finish_reason: Optional[FinishReason]
finish_reason: Optional[str]
index: int


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
ChatCompletionsResponse,
ChatCompletionsUsage,
ChatMessage,
FinishReason,
)
from dstack._internal.proxy.lib.services.model_proxy.clients.base import ChatCompletionsClient

Expand Down Expand Up @@ -180,7 +179,7 @@ def get_payload(self, request: ChatCompletionsRequest) -> Dict:
}

@staticmethod
def finish_reason(reason: str) -> FinishReason:
def finish_reason(reason: str) -> str:
if reason == "stop_sequence" or reason == "eos_token":
return "stop"
if reason == "length":
Expand Down

0 comments on commit 3918689

Please sign in to comment.