Skip to content

Commit 744d9cd

Browse files
ayushag-nvnv-anants
authored andcommitted
feat: added parsers lib (#2542)
1 parent 6ffc098 commit 744d9cd

File tree

18 files changed

+103
-45
lines changed

18 files changed

+103
-45
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"lib/tokens",
1212
"lib/async-openai",
1313
"lib/async-openai-macros",
14+
"lib/parsers",
1415
"lib/bindings/c",
1516
"lib/engines/*",
1617
]
@@ -32,6 +33,7 @@ dynamo-runtime = { path = "lib/runtime", version = "0.4.1" }
3233
dynamo-llm = { path = "lib/llm", version = "0.4.1" }
3334
dynamo-tokens = { path = "lib/tokens", version = "0.4.1" }
3435
dynamo-async-openai = { path = "lib/async-openai", version = "0.4.1", features = ["byot", "rustls"]}
36+
dynamo-parsers = { path = "lib/parsers", version = "0.4.1" }
3537

3638
# External dependencies
3739
anyhow = { version = "1" }

lib/llm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dynamo-runtime = { workspace = true }
4848
# workspace
4949
anyhow = { workspace = true }
5050
dynamo-async-openai = { workspace = true }
51+
dynamo-parsers = { workspace = true}
5152
async-stream = { workspace = true }
5253
async-trait = { workspace = true }
5354
async-nats = { workspace = true }

lib/llm/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ pub mod mocker;
2828
pub mod model_card;
2929
pub mod model_type;
3030
pub mod perf;
31-
pub mod postprocessor;
3231
pub mod preprocessor;
3332
pub mod protocols;
3433
pub mod recorder;

lib/llm/src/postprocessor/reasoning_parser.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/llm/src/postprocessor/reasoning_parser/parsers/mod.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

lib/llm/src/postprocessor/tool_calling/mod.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

lib/llm/src/protocols/openai/chat_completions/aggregator.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::protocols::{
2222
convert_sse_stream, Annotated,
2323
};
2424

25+
use dynamo_parsers::tool_calling::try_tool_call_parse_aggregate;
2526
use dynamo_runtime::engine::DataStream;
2627

2728
/// Aggregates a stream of [`NvCreateChatCompletionStreamResponse`]s into a single
@@ -163,12 +164,7 @@ impl DeltaAggregator {
163164
// After aggregation, inspect each choice's text for tool call syntax
164165
for choice in aggregator.choices.values_mut() {
165166
if choice.tool_calls.is_none() {
166-
if let Ok(tool_calls) =
167-
crate::postprocessor::tool_calling::tools::try_tool_call_parse_aggregate(
168-
&choice.text,
169-
None,
170-
)
171-
{
167+
if let Ok(tool_calls) = try_tool_call_parse_aggregate(&choice.text, None) {
172168
if tool_calls.is_empty() {
173169
continue;
174170
}

lib/parsers/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
[package]
17+
name = "dynamo-parsers"
18+
version.workspace = true
19+
edition.workspace = true
20+
description = "Dynamo Parser Library for Tool Calling and Reasoning"
21+
authors.workspace = true
22+
license.workspace = true
23+
homepage.workspace = true
24+
repository.workspace = true
25+
keywords.workspace = true
26+
27+
[dependencies]
28+
anyhow = { workspace = true }
29+
dynamo-async-openai = { workspace = true }
30+
serde = { workspace = true }
31+
serde_json = { workspace = true }
32+
tracing = { workspace = true }
33+
uuid = { workspace = true }
34+
35+
regex = "1"
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
pub mod reasoning_parser;
4+
pub mod reasoning;
55
pub mod tool_calling;
6+
7+
// Re-export everything from tool_calling for convenience
8+
pub use reasoning::*;
9+
pub use tool_calling::*;

0 commit comments

Comments
 (0)