Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tensorrt_llm/serve/openai_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ class ChatCompletionRequest(OpenAIBaseModel):
response_format: Optional[ResponseFormat] = None
seed: Optional[int] = Field(None)
stop: Optional[Union[str, List[str]]] = Field(default_factory=list)
# Standard OpenAI field, accepted for compatibility and otherwise ignored:
# the server keeps no copy of a chat completion, so there is nothing to
# store or to leave unstored.
store: Optional[bool] = None
stream: Optional[bool] = False
stream_options: Optional[StreamOptions] = None
temperature: Optional[float] = None
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_lists/test-db/l0_cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ l0_cpu:
- unittest/llmapi/apps/test_kimi_serve_extensions.py
- unittest/llmapi/apps/test_openai_chat_disagg_multimodal.py
- unittest/llmapi/apps/test_openai_chat_multimodal_prompt.py
- unittest/llmapi/apps/test_openai_protocol_chat_store.py
- unittest/llmapi/apps/test_openai_server_iteration_stats.py
- unittest/llmapi/apps/test_reasoning_prompt_resolution.py
- unittest/llmapi/apps/test_render_callers.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ models:
default: <factory:list>
status: stable
required: false
store:
kind: openai
type: Optional[bool]
default: null
status: stable
required: false
stream:
kind: openai
type: Optional[bool]
Expand Down
79 changes: 79 additions & 0 deletions tests/unittest/llmapi/apps/test_openai_protocol_chat_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# 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.
"""ChatCompletionRequest must accept the standard OpenAI `store` field.

The request schema is extra="forbid", so a request from an OpenAI client that
sets `store` (the pi coding agent sends `store: false` on every Chat
Completions request by default) failed validation with HTTP 400. The field is
accepted and not used: the server keeps no copy of a chat completion.
"""

import pytest
from pydantic import ValidationError

from tensorrt_llm.serve.openai_protocol import ChatCompletionRequest

pytestmark = pytest.mark.cpu_only


def _request(**extra) -> ChatCompletionRequest:
return ChatCompletionRequest(
model="test-model",
messages=[{"role": "user", "content": "hi"}],
**extra,
)


@pytest.mark.parametrize("value", [False, True, None])
def test_store_accepted(value):
assert _request(store=value).store is value


def test_store_defaults_to_none():
assert _request().store is None


def test_store_accepted_from_json():
req = ChatCompletionRequest.model_validate_json(
'{"model": "test-model", "messages": [{"role": "user", "content": "hi"}],'
' "store": false, "stream": true}'
)
assert req.store is False
assert req.stream is True


@pytest.mark.parametrize(
"value, expected", [("false", False), ("true", True), (0, False), (1, True)]
)
def test_store_coerces_boolean_like_values(value, expected):
# The request schema is not strict, so a boolean-like string or integer is
# coerced, as for every other boolean field of the request.
assert _request(store=value).store is expected


def test_store_rejects_a_value_that_is_not_boolean_like():
with pytest.raises(ValidationError):
Comment thread
JunyiXu-nv marked this conversation as resolved.
Resolved
_request(store={"keep": True})


def test_store_leaves_other_fields_unchanged():
plain = _request(temperature=0.5)
stored = _request(temperature=0.5, store=False)
assert stored.model_dump(exclude={"store"}) == plain.model_dump(exclude={"store"})


def test_unknown_fields_remain_rejected():
with pytest.raises(ValidationError):
_request(stores=False)
Loading