You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
- Add comparison JavaScript samples with Python.
Ticket: 175278
## Checklist:
- [x] Tests have been updated or added to cover the new code <!--- If
the change isn't maintenance related, update the tests at
https://github.com/openvinotoolkit/openvino.genai/tree/master/tests or
explain in the description why the tests don't need an update. -->
- [x] This patch fully addresses the ticket. <!--- If follow-up pull
requests are needed, specify in description. -->
- [ ] I have made corresponding changes to the documentation
---------
Signed-off-by: Kirill Suvorov <kirill.suvorov@intel.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: samples/js/text_generation/README.md
+8-5Lines changed: 8 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,27 +175,30 @@ If the model does not generate trigger strings there will be no structural const
175
175
The sample is verified with `meta-llama/Llama-3.2-3B-Instruct` model. Other models may not produce the expected results or might require different system prompt.
### 9. Compound Grammar Generation with Parsing Sample (`compound_grammar_generation`)
179
179
-**Description:**
180
-
This sample demonstrates advanced structured output generation using compound grammars in OpenVINO GenAI.
181
-
It showcases how to combine multiple grammar types - Regex, JSONSchema and EBNF - using Union and Concat operations to strictly control LLM output.
180
+
This sample demonstrates advanced structured output generation and results parsing using compound grammars in OpenVINO GenAI.
181
+
It showcases how to combine multiple grammar types - Regex, JSONSchema and EBNF - using Union and Concat operations to strictly control LLM output and
182
+
also shows how to write parsing logic to extract structured data from the generated output.
182
183
It features multi-turn chat, switching grammar constraints between turns (e.g., "yes"/"no" answers and structured tool calls).
183
184
Union operation allows the model to choose which grammar to use during generation.
184
185
In the sample it is used to combine two regex grammars for `"yes"` or `"no"` answer.
185
-
Concat operation allows to start with one grammar and continue with another.
186
+
Concat operation allows to start with one grammar and continue with another.
187
+
Also it demonstrates how to write custom parser to extract tool calls from the generated text.
186
188
In the sample it used to create a `phi-4-mini-instruct` style tool calling answer - `functools[{tool_1_json}, ...]` - by combining regex and JSON schema grammars.
187
189
188
190
-**Main Features:**
189
191
- Create grammar building blocks: Regex, JSONSchema, EBNF grammar
190
192
- Combine grammars with Concat and Union operations
191
193
- Multi-turn chat with grammar switching
192
194
- Structured tool calling using zod schemas
195
+
- Parse generated output to call tools from extracted structured data
193
196
-**Run Command:**
194
197
```bash
195
198
node compound_grammar_generation.js model_dir
196
199
```
197
200
-**Notes:**
198
-
This sample is ideal for scenarios requiring strict control over LLM outputs, such as building agents that interact with APIs or require validated structured responses. It showcases how to combine regex triggers and JSON schema enforcement for robust output generation.
201
+
This sample is ideal for scenarios requiring strict control over LLM outputs, such as building agents that interact with APIs or require validated structured responses. It showcases how to combine regex triggers and JSON schema enforcement for robust output generation and parsing resulting output.
199
202
The sample is verified with `microsoft/Phi-4-mini-instruct` model. Other models may not produce the expected results or might require different system prompt.
You can answer yes or no to questions, or you can choose to call one or more of the provided functions.
66
89
67
90
Use the following rule to decide when to call a function:
68
91
* if the response can be generated from your internal knowledge, do so, but use only yes or no as the response
69
92
* if you need external information that can be obtained by calling one or more of the provided functions, generate function calls
70
-
93
+
71
94
If you decide to call functions:
72
95
* prefix function calls with functools marker (no closing marker required)
73
96
* all function calls should be generated in a single JSON list formatted as functools[{"name": [function name], "arguments": [function arguments as JSON]}, ...]
74
97
* follow the provided JSON schema. Do not hallucinate arguments or values. Do not blindly copy values from the provided samples
75
98
* respect the argument type formatting. E.g., if the type is number and format is float, write value 7 as 7.0
76
99
* make sure you pick the right functions that match the user intent
0 commit comments