-
Notifications
You must be signed in to change notification settings - Fork 302
write chunks in TextParserStreamer #3025
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
7
commits into
openvinotoolkit:master
Choose a base branch
from
pavel-esir:write_chunks_during_parse
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.
+246
−130
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2be242f
write chunks in TextParserStreamer
pavel-esir 4017fb5
Fix pytests and gtests for parsers
pavel-esir 6e5dcc2
get rid of 'ensure_message_fields'; extend texts
pavel-esir ae2f662
Apply suggestions from code review
pavel-esir a8764fe
Apply suggestions from code review
pavel-esir 23fa222
use 'JsonContainer::concatenate'; improve variable naming
pavel-esir 3a8e302
Update src/cpp/src/parsers.cpp
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| from utils.hugging_face import convert_and_save_tokenizer, download_and_convert_model | ||
| from utils.ov_genai_pipelines import create_ov_pipeline | ||
| import pytest | ||
| from openvino_genai import Tokenizer, IncrementalParser, Parser, TextParserStreamer, StreamingStatus, Llama3JsonToolParser, Phi4ReasoningParser, Phi4ReasoningIncrementalParser, DeepSeekR1ReasoningIncrementalParser, GenerationConfig, ReasoningIncrementalParser | ||
| from openvino_genai import Tokenizer, IncrementalParser, Parser, TextParserStreamer, StreamingStatus, Llama3JsonToolParser, Phi4ReasoningParser, ReasoningParser, Phi4ReasoningIncrementalParser, DeepSeekR1ReasoningIncrementalParser, GenerationConfig, ReasoningIncrementalParser | ||
| from transformers import AutoTokenizer | ||
| import re | ||
|
|
||
|
|
@@ -51,13 +51,13 @@ def write(self, message): | |
| return StreamingStatus.RUNNING | ||
| streamer = CustomStreamer(genai_tokenizer, parsers=[Phi4ReasoningIncrementalParser()]) | ||
|
|
||
| msg = {} | ||
| for subword in stream_string: | ||
| streamer._write(subword) | ||
|
|
||
| think_content = answer.split("</think>")[0].replace("<think>", "") | ||
| content = answer | ||
|
|
||
|
|
||
| msg = streamer.get_parsed_message() | ||
| assert msg['reasoning_content'] == think_content | ||
| assert msg['content'] == content | ||
|
|
||
|
|
@@ -161,17 +161,17 @@ def test_incremental_phi4_reason_parser_2(hf_ov_genai_models, split_answer): | |
|
|
||
| class CustomStreamer(TextParserStreamer): | ||
| def write(self, message): | ||
| msg.update(message) | ||
| # will be accumulated automatically inside streamer | ||
| return StreamingStatus.RUNNING | ||
| streamer = CustomStreamer(genai_tokenizer, parsers=[Phi4ReasoningIncrementalParser()]) | ||
|
|
||
| msg = {} | ||
| for subword in split_answer: | ||
| streamer._write(subword) | ||
|
|
||
| think_content = (''.join(split_answer)).split("</think>")[0].replace("<think>", "") | ||
| content = ''.join(split_answer) | ||
| content = (''.join(split_answer).split("</think>")[1]) | ||
|
|
||
| msg = streamer.get_parsed_message() | ||
| assert msg['reasoning_content'] == think_content | ||
| assert msg['content'] == content | ||
|
|
||
|
|
@@ -378,7 +378,7 @@ def write(self, message): | |
| streamer = CustomStreamer(tok, parsers=[Phi4ReasoningIncrementalParser()]) | ||
|
|
||
| prompt = "Please say \"hello\"" | ||
| res = pipe.generate([prompt], max_new_tokens=600, parsers=[Phi4ReasoningParser()]) | ||
| res = pipe.generate([prompt], max_new_tokens=600, parsers=[ReasoningParser(keep_original_content=False)]) | ||
|
||
|
|
||
| # extract manually reasoning content from the parsed result | ||
| content = res.texts[0] | ||
|
|
||
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.