Skip to content
Merged
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a80c60b
keep full tools in request
chen700564 May 22, 2025
deee339
fix the type of function.arguments in message
chen700564 May 22, 2025
e162388
Merge branch 'sgl-project:main' into tool_call_fix
chen700564 May 23, 2025
e078c23
Merge branch 'sgl-project:main' into tool_call_fix
chen700564 May 23, 2025
bb70cee
update
chen700564 May 23, 2025
057db59
Merge branch 'main' into tool_call_fix
zhaochenyang20 May 23, 2025
77d828b
Merge branch 'main' into tool_call_fix
chen700564 Jun 13, 2025
fe4f823
Update adapter.py
chen700564 Jun 13, 2025
c7ad4d8
Update adapter.py
chen700564 Jun 13, 2025
c810d40
Merge branch 'main' into tool_call_fix
chen700564 Jun 18, 2025
f68d4a0
Add back the comment at L1096 originally
chen700564 Jun 20, 2025
70ea1c3
remove out-of-date code block
chen700564 Jun 20, 2025
9a9e07c
Merge branch 'sgl-project:main' into tool_call_fix
chen700564 Jun 21, 2025
b6a751d
pre-commit fix
chen700564 Jun 21, 2025
0850811
Delete python/sglang/srt/openai_api/adapter.py
chen700564 Jun 23, 2025
b39295a
Merge branch 'sgl-project:main' into tool_call_fix
chen700564 Jun 23, 2025
b66b9be
new version: keep full tools in request
chen700564 Jun 23, 2025
58a1003
new version: fix the type of function.arguments in OpenAI message
chen700564 Jun 23, 2025
78d9902
pre-commit fix
chen700564 Jun 23, 2025
b81fad3
Merge branch 'main' into tool_call_fix
chen700564 Jun 23, 2025
e8a1a0d
Merge branch 'main' into tool_call_fix
CatherineSue Jun 24, 2025
da42972
Merge branch 'main' into tool_call_fix
CatherineSue Jun 24, 2025
9cb2b3f
Merge branch 'main' into tool_call_fix
chen700564 Jun 25, 2025
d60516e
Merge branch 'main' into tool_call_fix
chen700564 Jun 30, 2025
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
40 changes: 33 additions & 7 deletions python/sglang/srt/openai_api/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,12 +1043,12 @@ def v1_chat_generate_request(
request.skip_special_tokens = False
if not isinstance(request.tool_choice, str):
tools = [
item.function.model_dump()
item.model_dump()
for item in request.tools
if item.function.name == request.tool_choice.function.name
]
else:
tools = [item.function.model_dump() for item in request.tools]
tools = [item.model_dump() for item in request.tools]

tool_call_parser = tokenizer_manager.server_args.tool_call_parser
parser = FunctionCallParser(request.tools, tool_call_parser)
Expand Down Expand Up @@ -1082,18 +1082,44 @@ def v1_chat_generate_request(
if message.content is None:
message.content = ""
msg_dict = message.model_dump()

# Process content based on detected template format

processed_msg = process_content_for_template_format(
msg_dict,
template_content_format,
image_data,
audio_data,
modalities,
)
openai_compatible_messages.append(processed_msg)

# Handle assistant prefix for continue_final_message

if (
"tool_calls" in processed_msg
and isinstance(processed_msg.get("tool_calls"), list)
):
for call in processed_msg["tool_calls"]:
try:
if (
"arguments" in call["function"]
and isinstance(call["function"]["arguments"], str)
):
call["function"]["arguments"] = json.loads(
call["function"]["arguments"]
)
except json.JSONDecodeError as e:
# Log a warning or error if JSON parsing fails for arguments
logger.warning(f"Failed to parse tool call arguments as JSON: {e}")
# Decide whether to continue or raise the exception based on desired behavior
continue # Or raise e if strict parsing is required
if isinstance(processed_msg.get("content"), list):
for chunk in processed_msg["content"]:
if isinstance(chunk, dict) and chunk.get("type") == "text":
new_msg = processed_msg.copy()
new_msg["content"] = chunk["text"]
new_msg = {
k: v for k, v in new_msg.items() if v is not None
}
openai_compatible_messages.append(new_msg)
else:
openai_compatible_messages.append(processed_msg)
if (
openai_compatible_messages
and openai_compatible_messages[-1]["role"] == "assistant"
Expand Down