-
Notifications
You must be signed in to change notification settings - Fork 312
[JS] Add support of Parser and default implementations #3132
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Kirill Suvorov <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds parser support to the JavaScript API, enabling users to process and transform generated text content. It provides both a base parser interface for custom JavaScript implementations and native wrapper classes for better performance.
Key changes include:
- Introduction of
JSParserclass that wraps JavaScript parser objects with thread-safe execution - Implementation of
ReasoningParserwrapper for extracting reasoning content from generated text - Extension of
GenerationConfigto accept an array of parsers that process content sequentially
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/js/tests/parsers.test.js | Comprehensive test suite covering custom parsers, ReasoningParser functionality, and parser integration with LLMPipeline |
| src/js/src/parser.cpp | Core implementation of JSParser (wraps JS parsers) and ReasoningParserWrapper (native parser wrapper) |
| src/js/src/llm_pipeline/llm_pipeline_wrapper.cpp | Adds parsed results to decoded results output |
| src/js/src/helper.cpp | Conversion utilities for parsers between JS and C++, including parser type detection and vector handling |
| src/js/src/addon.cpp | Exports ReasoningParser class to JavaScript |
| src/js/lib/utils.ts | Adds ParserGenerationConfig type definition |
| src/js/lib/pipelines/llmPipeline.ts | Updates DecodedResults to include parsed property |
| src/js/lib/parsers.ts | TypeScript type definitions for Parser interface and ReasoningParser options |
| src/js/lib/index.ts | Exports parser types to public API |
| src/js/lib/addon.ts | Adds ReasoningParser to addon exports |
| src/js/include/parser.hpp | Header declarations for JSParser and ReasoningParserWrapper classes |
| src/js/include/helper.hpp | Template declarations for parser conversion functions |
| src/js/include/addon.hpp | Adds reasoning_parser reference to AddonData structure |
| src/js/eslint.config.cjs | Adds reasoning_content to allowed snake_case identifiers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Register the addon with Node.js | ||
| NODE_API_MODULE(openvino-genai-node, init_module) | ||
| NODE_API_MODULE(openvino - genai - node, init_module) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does it change?
Description
This PR adds parsers to the JavaScript API.
The base parser can be a JavaScript object with parse methods. The user object is wrapped in a JSParser entity and uses TSFN.BlockingCall to execute it.
Child classes provide a wrapper that uses the core entity to parse the message. To boost performance, it doesn't use the JSParser and instead uses the native parser. If the user would like to extend it from the JavaScript side, it must be wrapped in a JSParser, just like the base parser.
The following child classes are supported:
The IncrementalParser is not supported now because it must be set up in the Streamer class, which the JS API does not support.
CVS-176151
Checklist: