Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] improve hermes_tool_parser.py #11444

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import json
import re
from typing import Dict, List, Sequence, Union
try:
from json_repair import json_repair
except ImportError:
# might remove codes below by adding json_repair in requirement.txt
import subprocess
subprocess.check_call(["pip", "install", "json_repair"])
from json_repair import json_repair
Copy link
Member

@DarkLight1337 DarkLight1337 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not install things automatically during runtime. Can you add this to the requirements file instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not install things automatically during runtime. Can you add this to the requirements file instead?

I noticed there are a lot of requirements files, and I'm not familiar with their specific uses. It might need some assistance with it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base dependencies of vLLM are contained in requirements-common.txt. Since tool parsing is applicable to all backends, you can add the dependency there.


import partial_json_parser
from partial_json_parser.core.options import Allow
Expand Down Expand Up @@ -82,7 +89,8 @@
# load the JSON, and then use it to build the Function and
# Tool Call
raw_function_calls = [
json.loads(match[0] if match[0] else match[1])
# Using json_repair can improve the robustness of parsing the JSON output

Check failure on line 92 in vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py

View workflow job for this annotation

GitHub Actions / ruff (3.12)

Ruff (E501)

vllm/entrypoints/openai/tool_parsers/hermes_tool_parser.py:92:81: E501 Line too long (93 > 80)
json_repair.loads(match[0] if match[0] else match[1])
for match in function_call_tuples
]
tool_calls = [
Expand Down
Loading