2024-11-22 22:16:53 +08:00
|
|
|
# Copyright 2023-2024 SGLang Team
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
|
#
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
#
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
|
# limitations under the License.
|
|
|
|
|
# ==============================================================================
|
2024-06-08 02:06:52 -07:00
|
|
|
"""Pydantic models for OpenAI API protocol"""
|
2024-05-14 22:40:46 +08:00
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
import time
|
|
|
|
|
from typing import Dict, List, Optional, Union
|
2024-01-08 04:37:50 +00:00
|
|
|
|
2025-05-19 18:21:29 -07:00
|
|
|
from pydantic import BaseModel, Field, root_validator
|
2024-01-30 16:36:10 +00:00
|
|
|
from typing_extensions import Literal
|
2024-01-08 04:37:50 +00:00
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
|
2024-07-20 02:15:21 +10:00
|
|
|
class ModelCard(BaseModel):
|
|
|
|
|
"""Model cards."""
|
|
|
|
|
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "model"
|
|
|
|
|
created: int = Field(default_factory=lambda: int(time.time()))
|
|
|
|
|
owned_by: str = "sglang"
|
|
|
|
|
root: Optional[str] = None
|
2025-03-27 23:23:18 -04:00
|
|
|
max_model_len: Optional[int] = None
|
2024-07-20 02:15:21 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModelList(BaseModel):
|
|
|
|
|
"""Model list consists of model cards."""
|
|
|
|
|
|
|
|
|
|
object: str = "list"
|
2024-11-14 19:09:21 -08:00
|
|
|
data: List[ModelCard] = Field(default_factory=list)
|
2024-07-20 02:15:21 +10:00
|
|
|
|
|
|
|
|
|
2024-05-20 18:41:21 -07:00
|
|
|
class ErrorResponse(BaseModel):
|
|
|
|
|
object: str = "error"
|
|
|
|
|
message: str
|
|
|
|
|
type: str
|
|
|
|
|
param: Optional[str] = None
|
|
|
|
|
code: int
|
|
|
|
|
|
|
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
class LogProbs(BaseModel):
|
|
|
|
|
text_offset: List[int] = Field(default_factory=list)
|
|
|
|
|
token_logprobs: List[Optional[float]] = Field(default_factory=list)
|
|
|
|
|
tokens: List[str] = Field(default_factory=list)
|
|
|
|
|
top_logprobs: List[Optional[Dict[str, float]]] = Field(default_factory=list)
|
|
|
|
|
|
|
|
|
|
|
2024-08-01 15:08:21 +08:00
|
|
|
class TopLogprob(BaseModel):
|
|
|
|
|
token: str
|
|
|
|
|
bytes: List[int]
|
|
|
|
|
logprob: float
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionTokenLogprob(BaseModel):
|
|
|
|
|
token: str
|
|
|
|
|
bytes: List[int]
|
|
|
|
|
logprob: float
|
|
|
|
|
top_logprobs: List[TopLogprob]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChoiceLogprobs(BaseModel):
|
|
|
|
|
# build for v1/chat/completions response
|
|
|
|
|
content: List[ChatCompletionTokenLogprob]
|
|
|
|
|
|
|
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
class UsageInfo(BaseModel):
|
|
|
|
|
prompt_tokens: int = 0
|
|
|
|
|
total_tokens: int = 0
|
|
|
|
|
completion_tokens: Optional[int] = 0
|
2024-10-16 20:49:22 +02:00
|
|
|
# only used to return cached tokens when --enable-cache-report is set
|
|
|
|
|
prompt_tokens_details: Optional[Dict[str, int]] = None
|
2024-01-18 17:00:56 -08:00
|
|
|
|
|
|
|
|
|
2024-08-08 17:41:57 +08:00
|
|
|
class StreamOptions(BaseModel):
|
|
|
|
|
include_usage: Optional[bool] = False
|
|
|
|
|
|
|
|
|
|
|
2024-09-09 19:08:25 -07:00
|
|
|
class JsonSchemaResponseFormat(BaseModel):
|
|
|
|
|
name: str
|
|
|
|
|
description: Optional[str] = None
|
|
|
|
|
# use alias to workaround pydantic conflict
|
|
|
|
|
schema_: Optional[Dict[str, object]] = Field(alias="schema", default=None)
|
|
|
|
|
strict: Optional[bool] = False
|
|
|
|
|
|
|
|
|
|
|
2024-07-30 04:07:18 +08:00
|
|
|
class FileRequest(BaseModel):
|
|
|
|
|
# https://platform.openai.com/docs/api-reference/files/create
|
|
|
|
|
file: bytes # The File object (not file name) to be uploaded
|
|
|
|
|
purpose: str = (
|
|
|
|
|
"batch" # The intended purpose of the uploaded file, default is "batch"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "file"
|
|
|
|
|
bytes: int
|
|
|
|
|
created_at: int
|
|
|
|
|
filename: str
|
|
|
|
|
purpose: str
|
|
|
|
|
|
|
|
|
|
|
2024-08-07 14:52:10 +08:00
|
|
|
class FileDeleteResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "file"
|
|
|
|
|
deleted: bool
|
|
|
|
|
|
|
|
|
|
|
2024-07-30 04:07:18 +08:00
|
|
|
class BatchRequest(BaseModel):
|
|
|
|
|
input_file_id: (
|
|
|
|
|
str # The ID of an uploaded file that contains requests for the new batch
|
|
|
|
|
)
|
|
|
|
|
endpoint: str # The endpoint to be used for all requests in the batch
|
|
|
|
|
completion_window: str # The time frame within which the batch should be processed
|
|
|
|
|
metadata: Optional[dict] = None # Optional custom metadata for the batch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BatchResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "batch"
|
|
|
|
|
endpoint: str
|
|
|
|
|
errors: Optional[dict] = None
|
|
|
|
|
input_file_id: str
|
|
|
|
|
completion_window: str
|
|
|
|
|
status: str = "validating"
|
|
|
|
|
output_file_id: Optional[str] = None
|
|
|
|
|
error_file_id: Optional[str] = None
|
|
|
|
|
created_at: int
|
|
|
|
|
in_progress_at: Optional[int] = None
|
|
|
|
|
expires_at: Optional[int] = None
|
|
|
|
|
finalizing_at: Optional[int] = None
|
|
|
|
|
completed_at: Optional[int] = None
|
|
|
|
|
failed_at: Optional[int] = None
|
|
|
|
|
expired_at: Optional[int] = None
|
|
|
|
|
cancelling_at: Optional[int] = None
|
|
|
|
|
cancelled_at: Optional[int] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
request_counts: Optional[dict] = None
|
2024-07-30 04:07:18 +08:00
|
|
|
metadata: Optional[dict] = None
|
|
|
|
|
|
|
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
class CompletionRequest(BaseModel):
|
2024-05-12 06:41:32 -07:00
|
|
|
# Ordered by official OpenAI API documentation
|
|
|
|
|
# https://platform.openai.com/docs/api-reference/completions/create
|
2024-01-18 17:00:56 -08:00
|
|
|
model: str
|
2024-05-12 06:41:32 -07:00
|
|
|
prompt: Union[List[int], List[List[int]], str, List[str]]
|
|
|
|
|
best_of: Optional[int] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
echo: bool = False
|
|
|
|
|
frequency_penalty: float = 0.0
|
2024-01-18 17:00:56 -08:00
|
|
|
logit_bias: Optional[Dict[str, float]] = None
|
2024-05-12 06:41:32 -07:00
|
|
|
logprobs: Optional[int] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
max_tokens: int = 16
|
2024-05-12 06:41:32 -07:00
|
|
|
n: int = 1
|
2024-11-14 19:09:21 -08:00
|
|
|
presence_penalty: float = 0.0
|
2024-05-12 06:41:32 -07:00
|
|
|
seed: Optional[int] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
stop: Optional[Union[str, List[str]]] = None
|
|
|
|
|
stream: bool = False
|
2024-08-08 17:41:57 +08:00
|
|
|
stream_options: Optional[StreamOptions] = None
|
2024-05-12 06:41:32 -07:00
|
|
|
suffix: Optional[str] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
temperature: float = 1.0
|
|
|
|
|
top_p: float = 1.0
|
2024-01-18 17:00:56 -08:00
|
|
|
user: Optional[str] = None
|
|
|
|
|
|
2024-02-10 17:21:33 -08:00
|
|
|
# Extra parameters for SRT backend only and will be ignored by OpenAI models.
|
2024-12-17 04:14:14 -08:00
|
|
|
top_k: int = -1
|
|
|
|
|
min_p: float = 0.0
|
2024-10-12 00:36:28 -07:00
|
|
|
min_tokens: int = 0
|
2024-12-17 04:14:14 -08:00
|
|
|
json_schema: Optional[str] = None
|
2024-12-29 23:57:16 -08:00
|
|
|
regex: Optional[str] = None
|
|
|
|
|
ebnf: Optional[str] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
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
|
2024-12-17 04:14:14 -08:00
|
|
|
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None
|
2025-01-16 12:51:11 -08:00
|
|
|
session_params: Optional[Dict] = None
|
2024-02-10 17:21:33 -08:00
|
|
|
|
2025-05-29 16:26:18 +08:00
|
|
|
# For PD disaggregation
|
|
|
|
|
bootstrap_host: Optional[str] = None
|
|
|
|
|
bootstrap_port: Optional[int] = None
|
|
|
|
|
bootstrap_room: Optional[int] = None
|
|
|
|
|
|
2024-01-18 17:00:56 -08:00
|
|
|
|
|
|
|
|
class CompletionResponseChoice(BaseModel):
|
|
|
|
|
index: int
|
|
|
|
|
text: str
|
|
|
|
|
logprobs: Optional[LogProbs] = None
|
2025-05-29 16:26:18 +08:00
|
|
|
finish_reason: Literal["stop", "length", "content_filter", "abort"]
|
2024-10-17 22:06:52 +04:00
|
|
|
matched_stop: Union[None, int, str] = None
|
2024-01-18 17:00:56 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompletionResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "text_completion"
|
|
|
|
|
created: int = Field(default_factory=lambda: int(time.time()))
|
|
|
|
|
model: str
|
|
|
|
|
choices: List[CompletionResponseChoice]
|
|
|
|
|
usage: UsageInfo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompletionResponseStreamChoice(BaseModel):
|
|
|
|
|
index: int
|
|
|
|
|
text: str
|
|
|
|
|
logprobs: Optional[LogProbs] = None
|
2025-03-27 15:16:52 +08:00
|
|
|
finish_reason: Optional[Literal["stop", "length", "content_filter"]] = None
|
2024-10-17 22:06:52 +04:00
|
|
|
matched_stop: Union[None, int, str] = None
|
2024-01-18 17:00:56 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class CompletionStreamResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "text_completion"
|
|
|
|
|
created: int = Field(default_factory=lambda: int(time.time()))
|
|
|
|
|
model: str
|
|
|
|
|
choices: List[CompletionResponseStreamChoice]
|
2024-08-08 17:41:57 +08:00
|
|
|
usage: Optional[UsageInfo] = None
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
|
2024-01-30 23:12:33 +09:00
|
|
|
class ChatCompletionMessageContentTextPart(BaseModel):
|
|
|
|
|
type: Literal["text"]
|
|
|
|
|
text: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionMessageContentImageURL(BaseModel):
|
|
|
|
|
url: str
|
|
|
|
|
detail: Optional[Literal["auto", "low", "high"]] = "auto"
|
|
|
|
|
|
|
|
|
|
|
2025-03-25 11:08:40 +08:00
|
|
|
class ChatCompletionMessageContentAudioURL(BaseModel):
|
|
|
|
|
url: str
|
|
|
|
|
|
|
|
|
|
|
2024-01-30 23:12:33 +09:00
|
|
|
class ChatCompletionMessageContentImagePart(BaseModel):
|
|
|
|
|
type: Literal["image_url"]
|
|
|
|
|
image_url: ChatCompletionMessageContentImageURL
|
2024-09-09 17:07:34 +08:00
|
|
|
modalities: Optional[Literal["image", "multi-images", "video"]] = "image"
|
2024-01-30 23:12:33 +09:00
|
|
|
|
|
|
|
|
|
2025-03-25 11:08:40 +08:00
|
|
|
class ChatCompletionMessageContentAudioPart(BaseModel):
|
|
|
|
|
type: Literal["audio_url"]
|
|
|
|
|
audio_url: ChatCompletionMessageContentAudioURL
|
|
|
|
|
|
|
|
|
|
|
2024-01-30 23:12:33 +09:00
|
|
|
ChatCompletionMessageContentPart = Union[
|
2025-03-25 11:08:40 +08:00
|
|
|
ChatCompletionMessageContentTextPart,
|
|
|
|
|
ChatCompletionMessageContentImagePart,
|
|
|
|
|
ChatCompletionMessageContentAudioPart,
|
2024-01-30 23:12:33 +09:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2025-05-06 02:43:34 +08:00
|
|
|
class FunctionResponse(BaseModel):
|
|
|
|
|
"""Function response."""
|
|
|
|
|
|
|
|
|
|
name: Optional[str] = None
|
|
|
|
|
arguments: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolCall(BaseModel):
|
|
|
|
|
"""Tool call response."""
|
|
|
|
|
|
|
|
|
|
id: Optional[str] = None
|
|
|
|
|
index: Optional[int] = None
|
|
|
|
|
type: Literal["function"] = "function"
|
|
|
|
|
function: FunctionResponse
|
|
|
|
|
|
|
|
|
|
|
2024-08-30 11:51:44 -07:00
|
|
|
class ChatCompletionMessageGenericParam(BaseModel):
|
2024-11-18 17:06:59 +08:00
|
|
|
role: Literal["system", "assistant", "tool"]
|
2025-04-21 08:15:38 +08:00
|
|
|
content: Union[str, List[ChatCompletionMessageContentTextPart], None]
|
2025-05-06 02:43:34 +08:00
|
|
|
tool_call_id: Optional[str] = None
|
|
|
|
|
name: Optional[str] = None
|
|
|
|
|
reasoning_content: Optional[str] = None
|
|
|
|
|
tool_calls: Optional[List[ToolCall]] = Field(default=None, examples=[None])
|
2024-08-30 11:51:44 -07:00
|
|
|
|
|
|
|
|
|
2024-01-30 23:12:33 +09:00
|
|
|
class ChatCompletionMessageUserParam(BaseModel):
|
|
|
|
|
role: Literal["user"]
|
|
|
|
|
content: Union[str, List[ChatCompletionMessageContentPart]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChatCompletionMessageParam = Union[
|
|
|
|
|
ChatCompletionMessageGenericParam, ChatCompletionMessageUserParam
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
2024-05-12 06:41:32 -07:00
|
|
|
class ResponseFormat(BaseModel):
|
2024-09-09 19:08:25 -07:00
|
|
|
type: Literal["text", "json_object", "json_schema"]
|
|
|
|
|
json_schema: Optional[JsonSchemaResponseFormat] = None
|
2024-05-12 06:41:32 -07:00
|
|
|
|
|
|
|
|
|
2025-02-28 15:33:41 +08:00
|
|
|
class StructuresResponseFormat(BaseModel):
|
|
|
|
|
begin: str
|
|
|
|
|
schema_: Optional[Dict[str, object]] = Field(alias="schema", default=None)
|
|
|
|
|
end: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StructuralTagResponseFormat(BaseModel):
|
|
|
|
|
type: Literal["structural_tag"]
|
|
|
|
|
structures: List[StructuresResponseFormat]
|
|
|
|
|
triggers: List[str]
|
|
|
|
|
|
|
|
|
|
|
2024-12-29 11:28:52 +05:30
|
|
|
class Function(BaseModel):
|
|
|
|
|
"""Function descriptions."""
|
|
|
|
|
|
|
|
|
|
description: Optional[str] = Field(default=None, examples=[None])
|
2025-01-26 09:57:51 -08:00
|
|
|
name: Optional[str] = None
|
2024-12-29 11:28:52 +05:30
|
|
|
parameters: Optional[object] = None
|
2025-03-25 14:15:25 +09:00
|
|
|
strict: bool = False
|
2024-12-29 11:28:52 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class Tool(BaseModel):
|
|
|
|
|
"""Function wrapper."""
|
|
|
|
|
|
|
|
|
|
type: str = Field(default="function", examples=["function"])
|
|
|
|
|
function: Function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolChoiceFuncName(BaseModel):
|
|
|
|
|
"""The name of tool choice function."""
|
|
|
|
|
|
2025-01-26 09:57:51 -08:00
|
|
|
name: Optional[str] = None
|
2024-12-29 11:28:52 +05:30
|
|
|
|
|
|
|
|
|
|
|
|
|
class ToolChoice(BaseModel):
|
|
|
|
|
"""The tool choice definition."""
|
|
|
|
|
|
|
|
|
|
function: ToolChoiceFuncName
|
|
|
|
|
type: Literal["function"] = Field(default="function", examples=["function"])
|
|
|
|
|
|
|
|
|
|
|
2024-01-18 23:43:09 -08:00
|
|
|
class ChatCompletionRequest(BaseModel):
|
2024-05-12 06:41:32 -07:00
|
|
|
# Ordered by official OpenAI API documentation
|
|
|
|
|
# https://platform.openai.com/docs/api-reference/chat/create
|
|
|
|
|
messages: List[ChatCompletionMessageParam]
|
2024-01-18 23:43:09 -08:00
|
|
|
model: str
|
2024-11-14 19:09:21 -08:00
|
|
|
frequency_penalty: float = 0.0
|
2024-05-12 06:41:32 -07:00
|
|
|
logit_bias: Optional[Dict[str, float]] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
logprobs: bool = False
|
2024-05-12 06:41:32 -07:00
|
|
|
top_logprobs: Optional[int] = None
|
2025-04-28 13:50:13 -07:00
|
|
|
max_tokens: Optional[int] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
deprecated="max_tokens is deprecated in favor of the max_completion_tokens field",
|
|
|
|
|
description="The maximum number of tokens that can be generated in the chat completion. ",
|
|
|
|
|
)
|
|
|
|
|
max_completion_tokens: Optional[int] = Field(
|
|
|
|
|
default=None,
|
|
|
|
|
description="The maximum number of completion tokens for a chat completion request, "
|
|
|
|
|
"including visible output tokens and reasoning tokens. Input tokens are not included. ",
|
|
|
|
|
)
|
2024-11-14 19:09:21 -08:00
|
|
|
n: int = 1
|
|
|
|
|
presence_penalty: float = 0.0
|
2025-03-28 05:19:05 +00:00
|
|
|
response_format: Optional[Union[ResponseFormat, StructuralTagResponseFormat]] = None
|
2024-05-12 06:41:32 -07:00
|
|
|
seed: Optional[int] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
stop: Optional[Union[str, List[str]]] = None
|
|
|
|
|
stream: bool = False
|
2024-08-08 17:41:57 +08:00
|
|
|
stream_options: Optional[StreamOptions] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
temperature: float = 0.7
|
|
|
|
|
top_p: float = 1.0
|
2024-01-18 23:43:09 -08:00
|
|
|
user: Optional[str] = None
|
2024-12-29 11:28:52 +05:30
|
|
|
tools: Optional[List[Tool]] = Field(default=None, examples=[None])
|
|
|
|
|
tool_choice: Union[ToolChoice, Literal["auto", "required", "none"]] = Field(
|
|
|
|
|
default="auto", examples=["none"]
|
|
|
|
|
) # noqa
|
2024-01-18 23:43:09 -08:00
|
|
|
|
2025-03-17 09:53:43 +08:00
|
|
|
@root_validator(pre=True)
|
|
|
|
|
def set_tool_choice_default(cls, values):
|
|
|
|
|
if values.get("tool_choice") is None:
|
|
|
|
|
if values.get("tools") is None:
|
|
|
|
|
values["tool_choice"] = "none"
|
|
|
|
|
else:
|
|
|
|
|
values["tool_choice"] = "auto"
|
|
|
|
|
return values
|
|
|
|
|
|
2024-02-10 17:21:33 -08:00
|
|
|
# Extra parameters for SRT backend only and will be ignored by OpenAI models.
|
2024-12-17 04:14:14 -08:00
|
|
|
top_k: int = -1
|
|
|
|
|
min_p: float = 0.0
|
2024-11-14 19:09:21 -08:00
|
|
|
min_tokens: int = 0
|
2024-12-17 04:14:14 -08:00
|
|
|
regex: Optional[str] = None
|
2024-12-29 23:57:16 -08:00
|
|
|
ebnf: Optional[str] = None
|
2024-11-14 19:09:21 -08:00
|
|
|
repetition_penalty: float = 1.0
|
|
|
|
|
stop_token_ids: Optional[List[int]] = None
|
|
|
|
|
no_stop_trim: bool = False
|
2024-10-12 00:36:28 -07:00
|
|
|
ignore_eos: bool = False
|
2025-04-21 06:07:18 +05:30
|
|
|
continue_final_message: bool = False
|
2024-11-14 19:09:21 -08:00
|
|
|
skip_special_tokens: bool = True
|
2024-12-17 04:14:14 -08:00
|
|
|
lora_path: Optional[Union[List[Optional[str]], Optional[str]]] = None
|
2025-01-16 12:51:11 -08:00
|
|
|
session_params: Optional[Dict] = None
|
2025-03-04 13:16:36 +08:00
|
|
|
separate_reasoning: bool = True
|
|
|
|
|
stream_reasoning: bool = True
|
2025-04-28 22:07:45 +08:00
|
|
|
chat_template_kwargs: Optional[Dict] = None
|
2024-02-10 17:21:33 -08:00
|
|
|
|
2025-05-18 09:58:22 +08:00
|
|
|
# The request id.
|
2025-05-18 13:05:38 -07:00
|
|
|
rid: Optional[str] = None
|
2025-05-18 09:58:22 +08:00
|
|
|
|
2025-04-21 16:10:58 +08:00
|
|
|
# For PD disaggregation
|
|
|
|
|
bootstrap_host: Optional[str] = None
|
2025-04-29 02:13:04 +08:00
|
|
|
bootstrap_port: Optional[int] = None
|
2025-04-21 16:10:58 +08:00
|
|
|
bootstrap_room: Optional[int] = None
|
|
|
|
|
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
class ChatMessage(BaseModel):
|
|
|
|
|
role: Optional[str] = None
|
|
|
|
|
content: Optional[str] = None
|
2025-03-04 13:16:36 +08:00
|
|
|
reasoning_content: Optional[str] = None
|
2024-12-29 11:28:52 +05:30
|
|
|
tool_calls: Optional[List[ToolCall]] = Field(default=None, examples=[None])
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionResponseChoice(BaseModel):
|
|
|
|
|
index: int
|
|
|
|
|
message: ChatMessage
|
2024-08-01 15:08:21 +08:00
|
|
|
logprobs: Optional[Union[LogProbs, ChoiceLogprobs]] = None
|
2025-03-27 15:16:52 +08:00
|
|
|
finish_reason: Literal[
|
2025-05-28 15:39:46 +08:00
|
|
|
"stop", "length", "tool_calls", "content_filter", "function_call", "abort"
|
2025-03-27 15:16:52 +08:00
|
|
|
]
|
2024-10-17 22:06:52 +04:00
|
|
|
matched_stop: Union[None, int, str] = None
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "chat.completion"
|
|
|
|
|
created: int = Field(default_factory=lambda: int(time.time()))
|
|
|
|
|
model: str
|
|
|
|
|
choices: List[ChatCompletionResponseChoice]
|
|
|
|
|
usage: UsageInfo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeltaMessage(BaseModel):
|
|
|
|
|
role: Optional[str] = None
|
|
|
|
|
content: Optional[str] = None
|
2025-03-04 13:16:36 +08:00
|
|
|
reasoning_content: Optional[str] = None
|
2025-01-26 09:57:51 -08:00
|
|
|
tool_calls: Optional[List[ToolCall]] = Field(default=None, examples=[None])
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionResponseStreamChoice(BaseModel):
|
|
|
|
|
index: int
|
|
|
|
|
delta: DeltaMessage
|
2024-08-05 07:43:09 +08:00
|
|
|
logprobs: Optional[Union[LogProbs, ChoiceLogprobs]] = None
|
2025-03-27 15:16:52 +08:00
|
|
|
finish_reason: Optional[
|
|
|
|
|
Literal["stop", "length", "tool_calls", "content_filter", "function_call"]
|
|
|
|
|
] = None
|
2024-10-17 22:06:52 +04:00
|
|
|
matched_stop: Union[None, int, str] = None
|
2024-01-18 23:43:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatCompletionStreamResponse(BaseModel):
|
|
|
|
|
id: str
|
|
|
|
|
object: str = "chat.completion.chunk"
|
|
|
|
|
created: int = Field(default_factory=lambda: int(time.time()))
|
|
|
|
|
model: str
|
2024-05-14 22:40:46 +08:00
|
|
|
choices: List[ChatCompletionResponseStreamChoice]
|
2024-08-08 17:41:57 +08:00
|
|
|
usage: Optional[UsageInfo] = None
|
2024-08-08 00:52:31 -07:00
|
|
|
|
|
|
|
|
|
2025-03-07 08:46:20 +08:00
|
|
|
class MultimodalEmbeddingInput(BaseModel):
|
|
|
|
|
text: Optional[str] = None
|
|
|
|
|
image: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
2024-08-08 00:52:31 -07:00
|
|
|
class EmbeddingRequest(BaseModel):
|
|
|
|
|
# Ordered by official OpenAI API documentation
|
|
|
|
|
# https://platform.openai.com/docs/api-reference/embeddings/create
|
2025-03-07 08:46:20 +08:00
|
|
|
input: Union[
|
|
|
|
|
List[int], List[List[int]], str, List[str], List[MultimodalEmbeddingInput]
|
|
|
|
|
]
|
2024-08-08 00:52:31 -07:00
|
|
|
model: str
|
|
|
|
|
encoding_format: str = "float"
|
|
|
|
|
dimensions: int = None
|
|
|
|
|
user: Optional[str] = None
|
|
|
|
|
|
2025-05-18 13:05:38 -07:00
|
|
|
# The request id.
|
|
|
|
|
rid: Optional[str] = None
|
|
|
|
|
|
2024-08-08 00:52:31 -07:00
|
|
|
|
2024-08-09 11:19:18 -07:00
|
|
|
class EmbeddingObject(BaseModel):
|
|
|
|
|
embedding: List[float]
|
|
|
|
|
index: int
|
2024-08-08 00:52:31 -07:00
|
|
|
object: str = "embedding"
|
2024-08-09 11:19:18 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmbeddingResponse(BaseModel):
|
|
|
|
|
data: List[EmbeddingObject]
|
|
|
|
|
model: str
|
|
|
|
|
object: str = "list"
|
2024-08-08 17:41:57 +08:00
|
|
|
usage: Optional[UsageInfo] = None
|
2025-06-04 14:14:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScoringRequest(BaseModel):
|
|
|
|
|
query: Optional[Union[str, List[int]]] = (
|
|
|
|
|
None # Query text or pre-tokenized token IDs
|
|
|
|
|
)
|
|
|
|
|
items: Optional[Union[str, List[str], List[List[int]]]] = (
|
|
|
|
|
None # Item text(s) or pre-tokenized token IDs
|
|
|
|
|
)
|
|
|
|
|
label_token_ids: Optional[List[int]] = (
|
|
|
|
|
None # Token IDs to compute probabilities for
|
|
|
|
|
)
|
|
|
|
|
apply_softmax: bool = False
|
|
|
|
|
item_first: bool = False
|
|
|
|
|
model: str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ScoringResponse(BaseModel):
|
|
|
|
|
scores: List[
|
|
|
|
|
List[float]
|
|
|
|
|
] # List of lists of probabilities, each in the order of label_token_ids
|
|
|
|
|
model: str
|
|
|
|
|
usage: Optional[UsageInfo] = None
|
|
|
|
|
object: str = "scoring"
|