-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[Bugfix] Fix the bug in Hermes streaming parsing #20824
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
base: main
Are you sure you want to change the base?
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @pre-master, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request resolves a critical bug in the Hermes tool parser's streaming functionality. By introducing a JSON repair mechanism, it ensures that even partially or incorrectly formed JSON segments, which can occur during real-time streaming, are corrected before parsing. This enhancement directly addresses issues where tool call arguments were being misinterpreted or lost, leading to more reliable and accurate tool invocation.
Highlights
- Bugfix for Hermes Streaming Parser: Implemented a fix for a bug in the Hermes tool parser where streaming responses could lead to incorrect or missing function arguments in tool calls. This was observed when arguments like 'a' and 'b' were swapped or dropped.
- JSON Repair Integration: Integrated the
json_repair
library to automatically mend potentially malformed or incomplete JSON strings received during streaming. This ensures that thepartial_json_parser
receives valid input, improving the robustness of tool call extraction.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a fix for a bug in Hermes streaming parsing where tool call arguments were being parsed incorrectly. The fix involves using the json_repair
library to repair the potentially malformed JSON string from the model before parsing it.
if tool_call_portion is not None: | ||
# repair the JSON if needed | ||
tool_call_portion = repair_json(tool_call_portion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling repair_json
on every streaming delta might introduce a performance bottleneck, potentially leading to quadratic complexity (O(N^2)
) for long tool calls as tool_call_portion
grows with each token. Consider attempting to parse with partial_json_parser
first and only calling repair_json
if that fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in streaming mode, normally N = 1
Signed-off-by: zxy <zx0823y@163.com>
Signed-off-by: zxy <zx0823y@163.com>
Similar issues:#17614
The output of
python collect_env.py
setup command
python -m vllm.entrypoints.openai.api_server --port 8120 --host 0.0.0.0 --model /root/autodl-tmp/Qwen/Qwen3-4B --reasoning-parser qwen3 --enable_chunked_prefill --max_model_len 16384 --gpu_memory_utilization 0.9 --enable_chunked_prefill --enable-auto-tool-choice --tool-call-parser hermes --served-model-name qwen3_4btest case
curl -X POST http://localhost:8120/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "model": "qwen3_4b", "user": "67c5e4020fa954de27e61f55", "stream": true, "tools": [ { "type": "function", "function": { "name": "calculate_two_number", "description": "Calculate the sum of two numbers", "parameters": { "type": "object", "properties": { "a": { "type": "number", "description": "First number" }, "b": { "type": "number", "description": "Second number" } }, "required": [ "a", "b" ], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } } } ], "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Please compute 1 + 3?" } ] } ] }'