[Frontend] Add defer_loading and tool_reference support for Anthropic and OpenAI APIs (#40190)

Signed-off-by: JaredforReal <w13431838023@gmail.com>
Signed-off-by: sfeng33 <4florafeng@gmail.com>
Signed-off-by: chaunceyjiang <chaunceyjiang@gmail.com>
Co-authored-by: sfeng33 <4florafeng@gmail.com>
Co-authored-by: Chauncey <chaunceyjiang@gmail.com>
This commit is contained in:
Jared Wen
2026-04-29 04:35:50 -07:00
committed by GitHub
co-authored by sfeng33 Chauncey
parent 33f36d4260
commit 11b69129e2
5 changed files with 97 additions and 6 deletions
@@ -11,7 +11,7 @@ from openai.types.chat.chat_completion_audio import (
ChatCompletionAudio as OpenAIChatCompletionAudio,
)
from openai.types.chat.chat_completion_message import Annotation as OpenAIAnnotation
from pydantic import Field, PrivateAttr, model_validator
from pydantic import Field, PrivateAttr, model_serializer, model_validator
from vllm.config import ModelConfig
from vllm.config.utils import replace
@@ -139,6 +139,20 @@ class ChatCompletionStreamResponse(OpenAIBaseModel):
class ChatCompletionToolsParam(OpenAIBaseModel):
type: Literal["function"] = "function"
function: FunctionDefinition
defer_loading: bool | None = None
@model_validator(mode="after")
def _propagate_defer_loading(self) -> "ChatCompletionToolsParam":
if self.defer_loading is not None and self.function.defer_loading is None:
self.function.defer_loading = self.defer_loading
return self
@model_serializer(mode="wrap")
def _serialize(self, handler):
data = handler(self)
if self.defer_loading is None:
data.pop("defer_loading", None)
return data
class ChatCompletionNamedFunction(OpenAIBaseModel):