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
6 changes: 5 additions & 1 deletion python/src/edge0/server/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ def parse_chat_request(payload: dict) -> ChatRequest:
temperature=payload.get("temperature"),
top_p=payload.get("top_p"),
top_k=payload.get("top_k"),
max_tokens=payload.get("max_tokens"),
# OpenAI deprecated ``max_tokens`` in favour of
# ``max_completion_tokens``, which current SDKs and clients send.
max_tokens=(payload["max_completion_tokens"]
if payload.get("max_completion_tokens") is not None
else payload.get("max_tokens")),
seed=payload.get("seed"),
stream=bool(payload.get("stream", False)),
enable_thinking=payload.get("enable_thinking"),
Expand Down
8 changes: 8 additions & 0 deletions python/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ def test_parse_stream_flag_and_sampling():
assert req.stream is True


def test_parse_max_completion_tokens():
# The current OpenAI name for the limit; it wins over the deprecated
# ``max_tokens`` when a client sends both.
assert _req(max_completion_tokens=24).max_tokens == 24
assert _req(max_completion_tokens=24, max_tokens=16).max_tokens == 24
assert _req(max_completion_tokens=None, max_tokens=16).max_tokens == 16


def test_parse_preserves_tools_and_tool_choice():
req = _req(tools=_TOOLS, tool_choice="auto")
assert req.tools == _TOOLS
Expand Down
Loading