Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"lib/tokens",
"lib/async-openai",
"lib/async-openai-macros",
"lib/parsers",
"lib/bindings/c",
"lib/engines/*",
]
Expand All @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions lib/llm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion lib/llm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 0 additions & 19 deletions lib/llm/src/postprocessor/reasoning_parser.rs

This file was deleted.

5 changes: 0 additions & 5 deletions lib/llm/src/postprocessor/reasoning_parser/parsers/mod.rs

This file was deleted.

7 changes: 0 additions & 7 deletions lib/llm/src/postprocessor/tool_calling/mod.rs

This file was deleted.

8 changes: 2 additions & 6 deletions lib/llm/src/protocols/openai/chat_completions/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
35 changes: 35 additions & 0 deletions lib/parsers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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"
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// 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::*;
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
// 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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 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 {
Expand Down
9 changes: 9 additions & 0 deletions lib/parsers/src/reasoning/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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;
17 changes: 17 additions & 0 deletions lib/parsers/src/tool_calling/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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};
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
Loading