-
Notifications
You must be signed in to change notification settings - Fork 364
Add Harmony (GPT-OSS) Tool Calling Support in FL #973
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
Draft
Sayan Shaw (sayanshaw24)
wants to merge
4
commits into
main
Choose a base branch
from
sayanshaw/harmony
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6836b3c
Add ToolCallConfig and header-inspection mode for Harmony tool calling
2cdc513
Add ToolCallConfig, header-inspection mode, and Harmony unit tests
7566cd3
Fix GCC -Werror=missing-field-initializers in ToolCallConfig::Simple()
31e7937
Merge main into harmony, resolve chat_session.cc conflicts
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
sdk_v2/cpp/src/inferencing/generative/toolcalling/tool_call_config.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
| #include <regex> | ||
|
|
||
| namespace fl { | ||
|
|
||
| /// Data-driven configuration for tool-call parsing. | ||
| /// All format-specific knowledge is captured as data properties — no model-specific | ||
| /// code branches. A single accumulator interprets the config at runtime. | ||
| struct ToolCallConfig { | ||
| enum class Mode { | ||
| kSimple, // ChatML: bot → JSON body (has name+args) → eot | ||
| kHeaderInspection // Harmony: bot → header → message_token → args JSON → end_token | ||
| }; | ||
|
|
||
| Mode mode = Mode::kSimple; | ||
|
|
||
| // --- Header-inspection mode properties --- | ||
|
|
||
| /// Token that separates the header from the message body (e.g., "<|message|>") | ||
| std::string message_token; | ||
|
|
||
| /// Regex to match the header and extract the function name. | ||
| /// Capture group 1 = function name (e.g., "to=functions\\.(.+)" captures "get_weather") | ||
| std::string header_regex; | ||
|
|
||
| /// Token between header routing and channel info (e.g., "<|channel|>") | ||
| /// Used to trim the header before regex matching. | ||
| std::string channel_token; | ||
|
|
||
| /// All tokens that terminate a tool-call block. | ||
| /// For Harmony: both <|end|> (intermediate) and <|call|> (final/EOS) terminate. | ||
| /// For Simple mode: this is just {eot_marker} (populated from context). | ||
| std::vector<std::string> end_tokens; | ||
|
|
||
| // --- Factory methods --- | ||
|
|
||
| /// Default config for ChatML-style models (Phi, Qwen). | ||
| /// Markers come from ToolCallContext; this just sets mode = kSimple. | ||
| static ToolCallConfig Simple() { | ||
| ToolCallConfig cfg; | ||
| cfg.mode = Mode::kSimple; | ||
| return cfg; | ||
| } | ||
|
|
||
| /// Config for GPT-OSS (Harmony) models. | ||
| static ToolCallConfig Harmony() { | ||
| ToolCallConfig cfg; | ||
| cfg.mode = Mode::kHeaderInspection; | ||
| cfg.message_token = "<|message|>"; | ||
| cfg.header_regex = R"(to=functions\.(.+))"; | ||
| cfg.channel_token = "<|channel|>"; | ||
| cfg.end_tokens = {"<|end|>", "<|call|>"}; | ||
| return cfg; | ||
| } | ||
|
|
||
| /// Infer config from model type string (from genai_config.json "model.type"). | ||
| static ToolCallConfig FromModelType(const std::string& model_type) { | ||
| if (model_type == "gptoss") return Harmony(); | ||
|
sayanshaw24 marked this conversation as resolved.
|
||
| return Simple(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace fl | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.