Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
dynamo
Commits
526b02f1
Unverified
Commit
526b02f1
authored
Aug 20, 2025
by
Ayush Agarwal
Committed by
GitHub
Aug 20, 2025
Browse files
feat: added parsers lib (#2542)
parent
536280fc
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
103 additions
and
33 deletions
+103
-33
Cargo.lock
Cargo.lock
+14
-0
Cargo.toml
Cargo.toml
+2
-0
lib/llm/Cargo.toml
lib/llm/Cargo.toml
+1
-0
lib/llm/src/lib.rs
lib/llm/src/lib.rs
+0
-1
lib/llm/src/postprocessor/reasoning_parser.rs
lib/llm/src/postprocessor/reasoning_parser.rs
+0
-19
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
+2
-6
lib/parsers/Cargo.toml
lib/parsers/Cargo.toml
+35
-0
lib/parsers/src/lib.rs
lib/parsers/src/lib.rs
+5
-1
lib/parsers/src/reasoning/base_parser.rs
lib/parsers/src/reasoning/base_parser.rs
+15
-2
lib/parsers/src/reasoning/deepseek_r1_parser.rs
lib/parsers/src/reasoning/deepseek_r1_parser.rs
+3
-3
lib/parsers/src/reasoning/mod.rs
lib/parsers/src/reasoning/mod.rs
+9
-0
lib/parsers/src/tool_calling/json_parser.rs
lib/parsers/src/tool_calling/json_parser.rs
+0
-0
lib/parsers/src/tool_calling/mod.rs
lib/parsers/src/tool_calling/mod.rs
+17
-0
lib/parsers/src/tool_calling/parsers.rs
lib/parsers/src/tool_calling/parsers.rs
+0
-0
lib/parsers/src/tool_calling/response.rs
lib/parsers/src/tool_calling/response.rs
+0
-0
lib/parsers/src/tool_calling/tools.rs
lib/parsers/src/tool_calling/tools.rs
+0
-1
No files found.
Cargo.lock
View file @
526b02f1
...
...
@@ -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"
...
...
Cargo.toml
View file @
526b02f1
...
...
@@ -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"
}
...
...
lib/llm/Cargo.toml
View file @
526b02f1
...
...
@@ -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
}
...
...
lib/llm/src/lib.rs
View file @
526b02f1
...
...
@@ -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
;
...
...
lib/llm/src/postprocessor/reasoning_parser.rs
deleted
100644 → 0
View file @
536280fc
// 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
;
}
lib/llm/src/protocols/openai/chat_completions/aggregator.rs
View file @
526b02f1
...
...
@@ -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
;
}
...
...
lib/parsers/Cargo.toml
0 → 100644
View file @
526b02f1
# 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
lib/
llm/src/postprocessor/mod
.rs
→
lib/
parsers/src/lib
.rs
View file @
526b02f1
// 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
::
*
;
lib/
llm/src/postprocessor/reasoning_parser/parsers/base_reasoning
_parser.rs
→
lib/
parsers/src/reasoning/base
_parser.rs
View file @
526b02f1
// 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
{
...
...
lib/
llm/src/postprocessor/reasoning_parser/parsers
/deepseek_r1_
reasoning_
parser.rs
→
lib/
parsers/src/reasoning
/deepseek_r1_parser.rs
View file @
526b02f1
// 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
{
...
...
lib/
llm/src/postprocessor/reasoning_parser/parsers
/mod.rs
→
lib/
parsers/src/reasoning
/mod.rs
View file @
526b02f1
// 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
;
lib/
llm/src/postprocessor
/tool_calling/json_parser.rs
→
lib/
parsers/src
/tool_calling/json_parser.rs
View file @
526b02f1
File moved
lib/
llm/src/postprocessor
/tool_calling/mod.rs
→
lib/
parsers/src
/tool_calling/mod.rs
View file @
526b02f1
...
...
@@ -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
};
lib/
llm/src/postprocessor
/tool_calling/parsers.rs
→
lib/
parsers/src
/tool_calling/parsers.rs
View file @
526b02f1
File moved
lib/
llm/src/postprocessor
/tool_calling/response.rs
→
lib/
parsers/src
/tool_calling/response.rs
View file @
526b02f1
File moved
lib/
llm/src/postprocessor
/tool_calling/tools.rs
→
lib/
parsers/src
/tool_calling/tools.rs
View file @
526b02f1
...
...
@@ -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
::
*
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment