Skip to content
Closed
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
38 changes: 37 additions & 1 deletion vllm/entrypoints/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,13 @@
def need_builtin_tool_call(self) -> bool:
"""Return true if the last message is a MCP tool call"""
last_message = self.parser.chat_completion_messages[-1]["content"][-1]
if isinstance(last_message, FunctionCall):
# HACK: figure out which tools are MCP tools
if last_message.name == "code_interpreter" or last_message.name == "python":
if (
last_message.name == "code_interpreter"
or last_message.name == "python"
or last_message.name == "web_search_preview"
):

Check failure on line 267 in vllm/entrypoints/context.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (SIM102)

vllm/entrypoints/context.py:261:9: SIM102 Use a single `if` statement instead of nested `if` statements
return True

return False
Expand Down Expand Up @@ -290,6 +294,34 @@

return [message]

async def call_search_tool(
self, tool_session: Union["ClientSession", Tool], last_msg: FunctionCall
) -> list[Message]:
self.called_tools.add("browser")
if isinstance(tool_session, Tool):
return await tool_session.get_result(self)
if envs.VLLM_TOOL_JSON_ERROR_AUTOMATIC_RETRY:
try:
args = json.loads(last_msg.arguments)
except json.JSONDecodeError as e:
return _create_json_parse_error_messages(last_msg, e)
else:
args = json.loads(last_msg.arguments)
result = await tool_session.call_tool("search", args)
result_str = result.content[0].text

content = TextContent(text=result_str)
# author = Author(role=Role.TOOL, name="python")

message = CustomChatCompletionMessageParam(
role="tool",
content=[
ChatCompletionContentPartTextParam(text=content, type="text")
], # TODO: why is this nested?
)

return [message]

async def call_tool(self) -> list[CustomChatCompletionMessageParam]:
if not self.parser.chat_completion_messages:
return []
Expand All @@ -299,9 +331,13 @@
return await self.call_python_tool(
self._tool_sessions["python"], last_tool_request
)
elif last_tool_request.name == "web_search_preview":
return await self.call_search_tool(
self._tool_sessions["browser"], last_tool_request
)
# recipient = last_message.name == "code_interpreter"
# if recipient is not None and recipient.startswith("python"):
# return await self.call_python_tool(self._tool_sessions["python"], last_tool_request)

Check failure on line 340 in vllm/entrypoints/context.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

vllm/entrypoints/context.py:340:89: E501 Line too long (98 > 88)

def render_for_completion(self):
return [
Expand Down
Loading