-
Notifications
You must be signed in to change notification settings - Fork 291
Add parsing #2772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pavel-esir
wants to merge
39
commits into
openvinotoolkit:master
Choose a base branch
from
pavel-esir:add_parsing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add parsing #2772
Changes from 19 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
4b357ff
tests are green
pavel-esir 525a4d8
python api added
pavel-esir 3ab9757
refactored
pavel-esir 5624fc2
add parsing at the end of generate()
pavel-esir 3407d8f
hide map with predefined initialized parsers; add TODOs
pavel-esir 219827a
use JsonContainer
pavel-esir 4c3d443
fix processing with JsonContainer and make tests green again
pavel-esir 5ee48bf
add Llama32JsonToolParser
pavel-esir 248ccc6
rename ParsedMessage -> JsonContainer
pavel-esir 04064bf
make tests green again, apply copilot comments
pavel-esir ae1930b
revert sample
pavel-esir 2772c98
update pybind11 stubs
pavel-esir 94b8370
update stubs
pavel-esir 7759b48
replace starts_with_thinking -> starts_with_thinking; some other corr…
pavel-esir 5470b63
remove std::variant<std::string, std::shared_ptr<Parsers>>
pavel-esir 62bf17a
hide leftovers to m_pimpl
pavel-esir 4f75706
move defaults from class members to ctor default arguments
pavel-esir edc2c3e
return void instead of JsonContainer and keep modifying argument by r…
pavel-esir e4ac079
pass openv/close tag strings by reference instead of value
pavel-esir ca732ba
remvoe breakpoint()
pavel-esir d6a6ef7
Merge remote-tracking branch 'upstream/master' into add_parsing
pavel-esir 32356cb
use new JsonContainer to py::dict conversion approach
pavel-esir aefbd7b
fix segfault; some other fixes
pavel-esir 9c0422c
add export symbols
pavel-esir ac9dd8c
add more tests use unique_ptr
pavel-esir e4ff386
cleanup pybindings; rename Llama32 -> Llama3
pavel-esir 196a54c
corrected expect_open_tag behaviour, added some tests
pavel-esir 801d8fb
renamed parsers; removed ParserBase -> Parser; IncrementalParserBase …
pavel-esir 01d4224
renaming leftovers
pavel-esir fec8945
some corrections
pavel-esir 9fa7d01
hide TextParsedStreamerImplementation
pavel-esir a2307a2
remove redundant previous_text, previous_tokens, add docstrings
pavel-esir cada055
add decorator to call/reset parser before/after generate
pavel-esir b18ee75
add reset() method
pavel-esir 79d299e
put delta_tokens to parser as well
pavel-esir 14a3a7f
Merge remote-tracking branch 'upstream/master' into add_parsing
pavel-esir 775cf13
store compiled pattern as a member
pavel-esir d4bf6be
call parsers for ChatHistory as well; update caches
pavel-esir 8ddc2c4
use json_container_to_py_object when `parse()` is called from Python …
pavel-esir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (C) 2023-2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
| #include <string> | ||
| #include <memory> | ||
| #include <vector> | ||
| #include "openvino/genai/json_container.hpp" | ||
|
|
||
| namespace ov { | ||
| namespace genai { | ||
|
|
||
| class IncrementalParserBase { | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| IncrementalParserBase() = default; | ||
|
|
||
| // We return string which with filtered text to be added to content. | ||
| virtual std::string parse( | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| JsonContainer& msg, | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const std::string& previous_text, | ||
| std::string& delta_text, | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const std::optional<std::vector<int64_t>>& previous_tokens = std::nullopt, | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const std::optional<std::vector<int64_t>>& delta_tokens = std::nullopt | ||
| ) = 0; | ||
| }; | ||
|
|
||
| class ReasoningParser : public IncrementalParserBase { | ||
| private: | ||
| class ReasoningParserImpl; | ||
| std::shared_ptr<ReasoningParserImpl> m_impl; | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| ReasoningParser(bool expect_open_tag = true, | ||
| bool keep_original_content = true, | ||
| const std::string& open_tag = "<think>", | ||
| const std::string& close_tag = "</think>"); | ||
|
|
||
| std::string parse( | ||
| JsonContainer& msg, | ||
| const std::string& previous_text, | ||
| std::string& delta_text, | ||
| const std::optional<std::vector<int64_t>>& previous_tokens = std::nullopt, | ||
| const std::optional<std::vector<int64_t>>& delta_tokens = std::nullopt | ||
| ) override; | ||
| }; | ||
|
|
||
| class DeepSeekR1ReasoningParser : public ReasoningParser { | ||
| public: | ||
| explicit DeepSeekR1ReasoningParser(bool expect_open_tag = true) : ReasoningParser(expect_open_tag) {}; | ||
| }; | ||
|
|
||
| class Phi4ReasoningParser : public ReasoningParser { | ||
| public: | ||
| explicit Phi4ReasoningParser(bool expect_open_tag = false) : ReasoningParser(expect_open_tag) {}; | ||
| }; | ||
|
|
||
| class ParserBase { | ||
pavel-esir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| ParserBase() = default; | ||
| virtual void parse(JsonContainer& text) = 0; | ||
| }; | ||
|
|
||
| class Llama32PythonicToolParser : public ParserBase { | ||
| // Does not modify original content, only extracts and adds tool calls | ||
| public: | ||
| explicit Llama32PythonicToolParser(bool keep_original_content = true); | ||
| void parse(JsonContainer& input) override; | ||
| private: | ||
| class Llama32PythonicToolParserImpl; | ||
| std::shared_ptr<Llama32PythonicToolParserImpl> m_impl; | ||
| }; | ||
|
|
||
| class Llama32JsonToolParser : public ParserBase { | ||
| // Does not modify original content, only extracts and adds tool calls | ||
| public: | ||
| explicit Llama32JsonToolParser(bool keep_original_content = true); | ||
| void parse(JsonContainer& input) override; | ||
| private: | ||
| class Llama32JsonToolParserImpl; | ||
| std::shared_ptr<Llama32JsonToolParserImpl> m_impl; | ||
| }; | ||
|
|
||
| class BaseReasoningParser : public ParserBase{ | ||
| public: | ||
| BaseReasoningParser( | ||
| bool expect_open_tag = true, | ||
| bool keep_original_content = true, | ||
| const std::string& open_tag = "<think>", | ||
| const std::string& close_tag = "</think>"); | ||
| void parse(JsonContainer& input) override; | ||
| private: | ||
| class BaseReasoningParserImpl; | ||
| std::shared_ptr<BaseReasoningParserImpl> m_impl; | ||
| }; | ||
|
|
||
| } // namespace genai | ||
| } // namespace ov | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.