Skip to content

Commit eac63be

Browse files
authored
Fix: gracefully ignore unsupported OpenAI API parameters (#1261)
1 parent 8aea9a2 commit eac63be

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

lightllm/server/api_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing_extensions import deprecated
33
import uuid
44

5-
from pydantic import BaseModel, Field, field_validator, model_validator
5+
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
66
from typing import Any, Dict, List, Optional, Union, Literal, ClassVar
77
from transformers import GenerationConfig
88

@@ -116,6 +116,7 @@ def _normalize_role(cls, v):
116116

117117

118118
class CompletionRequest(BaseModel):
119+
model_config = ConfigDict(extra="ignore")
119120
model: str
120121
# prompt: string or tokens
121122
prompt: Union[str, List[str], List[int], List[List[int]]]
@@ -187,6 +188,7 @@ def apply_loaded_defaults(cls, data: Any):
187188

188189

189190
class ChatCompletionRequest(BaseModel):
191+
model_config = ConfigDict(extra="ignore")
190192
model: str
191193
messages: List[ChatCompletionMessageParam]
192194
function_call: Optional[str] = "none"

lightllm/server/api_openai.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,10 @@ async def chat_completions_impl(request: ChatCompletionRequest, raw_request: Req
180180
from .api_http import g_objs
181181

182182
if request.logit_bias is not None:
183-
return create_error_response(
184-
HTTPStatus.BAD_REQUEST,
185-
"The logit_bias parameter is not currently supported",
186-
)
183+
logger.debug("Received unsupported parameter 'logit_bias', ignoring")
187184

188185
if request.function_call != "none":
189-
return create_error_response(HTTPStatus.BAD_REQUEST, "The function call feature is not supported")
186+
logger.debug("Received unsupported parameter 'function_call', ignoring")
190187

191188
created_time = int(time.time())
192189

@@ -607,10 +604,7 @@ async def completions_impl(request: CompletionRequest, raw_request: Request) ->
607604
from .api_http import g_objs
608605

609606
if request.logit_bias is not None:
610-
return create_error_response(
611-
HTTPStatus.BAD_REQUEST,
612-
"The logit_bias parameter is not currently supported",
613-
)
607+
logger.debug("Received unsupported parameter 'logit_bias', ignoring")
614608

615609
created_time = int(time.time())
616610

@@ -638,10 +632,7 @@ async def completions_impl(request: CompletionRequest, raw_request: Request) ->
638632

639633
# Handle suffix for completion mode
640634
if request.suffix:
641-
return create_error_response(
642-
HTTPStatus.BAD_REQUEST,
643-
"The suffix parameter is not currently supported",
644-
)
635+
logger.debug("Received unsupported parameter 'suffix', ignoring")
645636

646637
# Prepare sampling parameters - same as g_generate_stream_func pattern
647638
sampling_params_dict = {

0 commit comments

Comments
 (0)