feat: Add vLLM tool parsing support in completions #646
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request adds support for parsing and extracting structured tool calls from model outputs in the generator, making it possible to handle tool-augmented chat completions. It introduces a configurable tool parser, updates the
Completiondata model to include tool call information, and adds comprehensive unit tests for both tool parsing and non-tool parsing scenarios.What this does
When users send requests with tool parsing enabled like this:
The completion object will now have:
completion.tool_calls- List of parsed tool calls from the model outputcompletion.has_tool_calls- Boolean property to check if any tool calls existcompletion.content- The text content excluding tool call tagsTo enable this, set tool_call_parser="hermes" when creating the policy.
Changes
Tool Parsing Integration:
tool_call_parseroption to theGeneratorclass and logic to initialize and use a tool parser for extracting tool calls from model output. [1] [2]_extract_tool_callsmethod to extract tool calls and content using the configured parser, handling exceptions gracefully. (src/forge/actors/generator.py)_to_completionsto populate the newtool_callsandcontentfields inCompletionwhen tool parsing is enabled. (src/forge/actors/generator.py) [1] [2]Data Model Enhancements:
Completionclass to includetool_calls,content, and ahas_tool_callsproperty for easier downstream usage. (src/forge/data_models/completion.py) [1] [2]Dependency Updates:
src/forge/actors/generator.py)Test plan
tests/unit_tests/test_generator.py)