[router] add harmony tool parser base structure and interface (#11036)
This commit is contained in:
70
sgl-router/src/tool_parser/parsers/gpt_oss_harmony_parser.rs
Normal file
70
sgl-router/src/tool_parser/parsers/gpt_oss_harmony_parser.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use async_trait::async_trait;
|
||||
|
||||
use crate::tool_parser::{
|
||||
errors::ToolParserResult,
|
||||
state::ParseState,
|
||||
traits::{TokenToolParser, ToolParser},
|
||||
types::{StreamResult, ToolCall},
|
||||
};
|
||||
|
||||
/// Placeholder for the Harmony-backed GPT-OSS parser.
|
||||
///
|
||||
/// regex implementation. This struct will be fleshed out in subsequent phases to
|
||||
/// reuse Harmony's tokenizer and message reconstruction logic.
|
||||
#[derive(Default)]
|
||||
pub struct GptOssHarmonyParser;
|
||||
|
||||
impl GptOssHarmonyParser {
|
||||
pub fn new() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl ToolParser for GptOssHarmonyParser {
|
||||
async fn parse_complete(&self, output: &str) -> ToolParserResult<(String, Vec<ToolCall>)> {
|
||||
// Temporary stub: fall back to returning the raw text with no tool calls.
|
||||
// Later phases will decode Harmony tokens into structured tool calls.
|
||||
Ok((output.to_string(), Vec::new()))
|
||||
}
|
||||
|
||||
async fn parse_incremental(
|
||||
&self,
|
||||
_chunk: &str,
|
||||
_state: &mut ParseState,
|
||||
) -> ToolParserResult<StreamResult> {
|
||||
// Temporary stub until the Harmony streaming pipeline is implemented.
|
||||
Ok(StreamResult::Incomplete)
|
||||
}
|
||||
|
||||
fn detect_format(&self, text: &str) -> bool {
|
||||
// Reuse the legacy heuristics for now; this will be replaced with Harmony-specific
|
||||
// start-token detection when the parser is fully implemented.
|
||||
text.contains("<|channel|>commentary")
|
||||
}
|
||||
|
||||
fn as_token_parser(&self) -> Option<&dyn TokenToolParser> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl TokenToolParser for GptOssHarmonyParser {
|
||||
async fn parse_complete_tokens(
|
||||
&self,
|
||||
_tokens: &[u32],
|
||||
) -> ToolParserResult<(String, Vec<ToolCall>)> {
|
||||
// Placeholder until Harmony integration lands. Returning an empty tool list ensures
|
||||
// that enabling the parser without full implementation results in a no-op rather
|
||||
// than a runtime panic.
|
||||
Ok((String::new(), Vec::new()))
|
||||
}
|
||||
|
||||
async fn parse_incremental_tokens(
|
||||
&self,
|
||||
_tokens: &[u32],
|
||||
_state: &mut ParseState,
|
||||
) -> ToolParserResult<StreamResult> {
|
||||
Ok(StreamResult::Incomplete)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
// Individual parser modules
|
||||
pub mod deepseek_parser;
|
||||
pub mod glm4_moe_parser;
|
||||
pub mod gpt_oss_harmony_parser;
|
||||
pub mod gpt_oss_parser;
|
||||
pub mod json_parser;
|
||||
pub mod kimik2_parser;
|
||||
@@ -17,6 +18,7 @@ pub mod step3_parser;
|
||||
// Re-export parser types for convenience
|
||||
pub use deepseek_parser::DeepSeekParser;
|
||||
pub use glm4_moe_parser::Glm4MoeParser;
|
||||
pub use gpt_oss_harmony_parser::GptOssHarmonyParser;
|
||||
pub use gpt_oss_parser::GptOssParser;
|
||||
pub use json_parser::JsonParser;
|
||||
pub use kimik2_parser::KimiK2Parser;
|
||||
|
||||
Reference in New Issue
Block a user