"...git@developer.sourcefind.cn:2222/OpenDAS/vllm_cscc.git" did not exist on "7ea6cb28b260c4b8aeeaf103a47efc7fd5f97982"
Unverified Commit 526b02f1 authored by Ayush Agarwal's avatar Ayush Agarwal Committed by GitHub
Browse files

feat: added parsers lib (#2542)

parent 536280fc
......@@ -1919,6 +1919,7 @@ dependencies = [
"derive_builder",
"dialoguer",
"dynamo-async-openai",
"dynamo-parsers",
"dynamo-runtime",
"either",
"erased-serde",
......@@ -1973,6 +1974,19 @@ dependencies = [
"zeromq",
]
[[package]]
name = "dynamo-parsers"
version = "0.4.1"
dependencies = [
"anyhow",
"dynamo-async-openai",
"regex",
"serde",
"serde_json",
"tracing",
"uuid 1.17.0",
]
[[package]]
name = "dynamo-run"
version = "0.4.1"
......
......@@ -11,6 +11,7 @@ members = [
"lib/tokens",
"lib/async-openai",
"lib/async-openai-macros",
"lib/parsers",
"lib/bindings/c",
"lib/engines/*",
]
......@@ -32,6 +33,7 @@ dynamo-runtime = { path = "lib/runtime", version = "0.4.1" }
dynamo-llm = { path = "lib/llm", version = "0.4.1" }
dynamo-tokens = { path = "lib/tokens", version = "0.4.1" }
dynamo-async-openai = { path = "lib/async-openai", version = "0.4.1", features = ["byot", "rustls"]}
dynamo-parsers = { path = "lib/parsers", version = "0.4.1" }
# External dependencies
anyhow = { version = "1" }
......
......@@ -48,6 +48,7 @@ dynamo-runtime = { workspace = true }
# workspace
anyhow = { workspace = true }
dynamo-async-openai = { workspace = true }
dynamo-parsers = { workspace = true}
async-stream = { workspace = true }
async-trait = { workspace = true }
async-nats = { workspace = true }
......
......@@ -28,7 +28,6 @@ pub mod mocker;
pub mod model_card;
pub mod model_type;
pub mod perf;
pub mod postprocessor;
pub mod preprocessor;
pub mod protocols;
pub mod recorder;
......
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
pub mod parsers;
pub struct ParserResult {
/// The normal text outside of reasoning blocks.
pub normal_text: String,
/// The extracted reasoning text from within reasoning blocks.
pub reasoning_text: String,
}
pub trait ReasoningParser {
/// Detects and parses reasoning from the input text.
fn detect_and_parse_reasoning(&mut self, text: &str) -> ParserResult;
/// Parses reasoning incrementally from streaming input.
fn parse_reasoning_streaming_incremental(&mut self, text: &str) -> ParserResult;
}
......@@ -22,6 +22,7 @@ use crate::protocols::{
convert_sse_stream, Annotated,
};
use dynamo_parsers::tool_calling::try_tool_call_parse_aggregate;
use dynamo_runtime::engine::DataStream;
/// Aggregates a stream of [`NvCreateChatCompletionStreamResponse`]s into a single
......@@ -163,12 +164,7 @@ impl DeltaAggregator {
// After aggregation, inspect each choice's text for tool call syntax
for choice in aggregator.choices.values_mut() {
if choice.tool_calls.is_none() {
if let Ok(tool_calls) =
crate::postprocessor::tool_calling::tools::try_tool_call_parse_aggregate(
&choice.text,
None,
)
{
if let Ok(tool_calls) = try_tool_call_parse_aggregate(&choice.text, None) {
if tool_calls.is_empty() {
continue;
}
......
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
[package]
name = "dynamo-parsers"
version.workspace = true
edition.workspace = true
description = "Dynamo Parser Library for Tool Calling and Reasoning"
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
[dependencies]
anyhow = { workspace = true }
dynamo-async-openai = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }
regex = "1"
\ No newline at end of file
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
pub mod reasoning_parser;
pub mod reasoning;
pub mod tool_calling;
// Re-export everything from tool_calling for convenience
pub use reasoning::*;
pub use tool_calling::*;
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
use tracing as log;
use crate::postprocessor::reasoning_parser::{ParserResult, ReasoningParser};
pub struct ParserResult {
/// The normal text outside of reasoning blocks.
pub normal_text: String,
use tracing as log;
/// The extracted reasoning text from within reasoning blocks.
pub reasoning_text: String,
}
pub trait ReasoningParser {
/// Detects and parses reasoning from the input text.
fn detect_and_parse_reasoning(&mut self, text: &str) -> ParserResult;
/// Parses reasoning incrementally from streaming input.
fn parse_reasoning_streaming_incremental(&mut self, text: &str) -> ParserResult;
}
#[derive(Default)]
pub struct BaseReasoningParser {
......
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
use crate::postprocessor::reasoning_parser::parsers::base_reasoning_parser::BaseReasoningParser;
use crate::postprocessor::reasoning_parser::{ParserResult, ReasoningParser};
use super::base_parser::BaseReasoningParser;
use super::base_parser::ParserResult;
use super::base_parser::ReasoningParser;
#[derive(Default)]
pub struct DeepseekR1ReasoningParser {
......
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
pub mod base_reasoning_parser;
pub mod deepseek_r1_reasoning_parser;
pub mod base_parser;
pub mod deepseek_r1_parser;
// Re-export main types and functions for convenience
pub use base_parser::ReasoningParser;
pub use deepseek_r1_parser::DeepseekR1ReasoningParser;
......@@ -5,3 +5,13 @@ pub mod json_parser;
pub mod parsers;
pub mod response;
pub mod tools;
// Re-export main types and functions for convenience
pub use json_parser::{
try_tool_call_parse_json, CalledFunctionArguments, CalledFunctionParameters,
};
pub use parsers::{
detect_and_parse_tool_call, JsonParserConfig, ToolCallConfig, ToolCallParserType,
};
pub use response::{CalledFunction, ToolCallResponse, ToolCallType};
pub use tools::{try_tool_call_parse_aggregate, try_tool_call_parse_stream};
......@@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
pub use super::response::*;
pub use crate::preprocessor::tools::request::*;
// Import json_parser from postprocessor module
pub use super::json_parser::*;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment