Skip to content
Open
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
57 changes: 31 additions & 26 deletions python/sglang/srt/openai_api/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,32 +948,6 @@ def v1_chat_generate_request(

if chat_template_name is None:
openai_compatible_messages = []
if (
tools
and tokenizer_manager.server_args.tool_call_parser == "deepseekv3"
):
# add function call prompt to deepseekv3
openai_compatible_messages.append(
{
"role": "system",
"content": """You are a helpful Assistant.
## Tools
### Function
You have the following functions available:
"""
+ "".join(
[
f"""
- `{tool['name']}`:
```json
{json.dumps(tool)}
```
"""
for tool in tools
]
),
}
)

for message in request.messages:
if message.content is None:
Expand All @@ -989,6 +963,37 @@ def v1_chat_generate_request(
openai_compatible_messages.append(
{"role": message.role, "content": content["text"]}
)
if (
tools
and tokenizer_manager.server_args.tool_call_parser == "deepseekv3"
):
tool_content = """You are a helpful Assistant.
## Tools
### Function
You have the following functions available:
""" + "".join(
[
f"""
- `{tool['name']}`:
```json
{json.dumps(tool)}
```
"""
for tool in tools
]
)
system_messages = [
msg
for msg in openai_compatible_messages
if msg["role"] == "system"
]

if system_messages:
system_messages[-1]["content"] += "\n" + tool_content
else:
openai_compatible_messages.insert(
0, {"role": "system", "content": tool_content}
)
if (
openai_compatible_messages
and openai_compatible_messages[-1]["role"] == "assistant"
Expand Down
Loading