@botpress/zai 1.0.0-beta.2 → 1.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/dist/index.cjs +1898 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +916 -0
  4. package/dist/index.d.ts +916 -0
  5. package/dist/index.js +1868 -0
  6. package/dist/index.js.map +1 -0
  7. package/ensure-env.cjs +9 -0
  8. package/package.json +25 -17
  9. package/tsconfig.json +23 -18
  10. package/tsup.config.ts +16 -0
  11. package/vitest.config.ts +2 -16
  12. package/vitest.setup.ts +11 -15
  13. package/dist/src/adapters/adapter.d.ts +0 -27
  14. package/dist/src/adapters/adapter.js +0 -3
  15. package/dist/src/adapters/adapter.js.map +0 -1
  16. package/dist/src/adapters/botpress-table.d.ts +0 -155
  17. package/dist/src/adapters/botpress-table.js +0 -170
  18. package/dist/src/adapters/botpress-table.js.map +0 -1
  19. package/dist/src/adapters/memory.d.ts +0 -7
  20. package/dist/src/adapters/memory.js +0 -13
  21. package/dist/src/adapters/memory.js.map +0 -1
  22. package/dist/src/env.d.ts +0 -1
  23. package/dist/src/env.js +0 -27
  24. package/dist/src/env.js.map +0 -1
  25. package/dist/src/index.d.ts +0 -9
  26. package/dist/src/index.js +0 -10
  27. package/dist/src/index.js.map +0 -1
  28. package/dist/src/models.d.ts +0 -253
  29. package/dist/src/models.js +0 -348
  30. package/dist/src/models.js.map +0 -1
  31. package/dist/src/operations/__tests/index.d.ts +0 -19
  32. package/dist/src/operations/__tests/index.js +0 -24
  33. package/dist/src/operations/__tests/index.js.map +0 -1
  34. package/dist/src/operations/check.d.ts +0 -36
  35. package/dist/src/operations/check.js +0 -146
  36. package/dist/src/operations/check.js.map +0 -1
  37. package/dist/src/operations/check.test.d.ts +0 -1
  38. package/dist/src/operations/check.test.js +0 -129
  39. package/dist/src/operations/check.test.js.map +0 -1
  40. package/dist/src/operations/constants.d.ts +0 -2
  41. package/dist/src/operations/constants.js +0 -3
  42. package/dist/src/operations/constants.js.map +0 -1
  43. package/dist/src/operations/errors.d.ts +0 -5
  44. package/dist/src/operations/errors.js +0 -11
  45. package/dist/src/operations/errors.js.map +0 -1
  46. package/dist/src/operations/extract.d.ts +0 -20
  47. package/dist/src/operations/extract.js +0 -235
  48. package/dist/src/operations/extract.js.map +0 -1
  49. package/dist/src/operations/extract.test.d.ts +0 -1
  50. package/dist/src/operations/extract.test.js +0 -163
  51. package/dist/src/operations/extract.test.js.map +0 -1
  52. package/dist/src/operations/filter.d.ts +0 -39
  53. package/dist/src/operations/filter.js +0 -184
  54. package/dist/src/operations/filter.js.map +0 -1
  55. package/dist/src/operations/filter.test.d.ts +0 -1
  56. package/dist/src/operations/filter.test.js +0 -151
  57. package/dist/src/operations/filter.test.js.map +0 -1
  58. package/dist/src/operations/label.d.ts +0 -79
  59. package/dist/src/operations/label.js +0 -250
  60. package/dist/src/operations/label.js.map +0 -1
  61. package/dist/src/operations/label.test.d.ts +0 -1
  62. package/dist/src/operations/label.test.js +0 -213
  63. package/dist/src/operations/label.test.js.map +0 -1
  64. package/dist/src/operations/rewrite.d.ts +0 -34
  65. package/dist/src/operations/rewrite.js +0 -106
  66. package/dist/src/operations/rewrite.js.map +0 -1
  67. package/dist/src/operations/rewrite.test.d.ts +0 -1
  68. package/dist/src/operations/rewrite.test.js +0 -96
  69. package/dist/src/operations/rewrite.test.js.map +0 -1
  70. package/dist/src/operations/summarize.d.ts +0 -46
  71. package/dist/src/operations/summarize.js +0 -139
  72. package/dist/src/operations/summarize.js.map +0 -1
  73. package/dist/src/operations/summarize.test.d.ts +0 -1
  74. package/dist/src/operations/summarize.test.js +0 -22
  75. package/dist/src/operations/summarize.test.js.map +0 -1
  76. package/dist/src/operations/text.d.ts +0 -16
  77. package/dist/src/operations/text.js +0 -47
  78. package/dist/src/operations/text.js.map +0 -1
  79. package/dist/src/operations/text.test.d.ts +0 -1
  80. package/dist/src/operations/text.test.js +0 -51
  81. package/dist/src/operations/text.test.js.map +0 -1
  82. package/dist/src/operations/zai-learn.test.d.ts +0 -1
  83. package/dist/src/operations/zai-learn.test.js +0 -71
  84. package/dist/src/operations/zai-learn.test.js.map +0 -1
  85. package/dist/src/operations/zai-retry.test.d.ts +0 -1
  86. package/dist/src/operations/zai-retry.test.js +0 -50
  87. package/dist/src/operations/zai-retry.test.js.map +0 -1
  88. package/dist/src/utils.d.ts +0 -53
  89. package/dist/src/utils.js +0 -49
  90. package/dist/src/utils.js.map +0 -1
  91. package/dist/src/zai.d.ts +0 -91
  92. package/dist/src/zai.js +0 -139
  93. package/dist/src/zai.js.map +0 -1
  94. package/dist/tsconfig.tsbuildinfo +0 -1
  95. package/dist/typings.d.ts +0 -901
  96. package/dist/typings.tsbuildinfo +0 -1
  97. package/dist/vitest.config.d.ts +0 -2
  98. package/dist/vitest.config.js +0 -21
  99. package/dist/vitest.config.js.map +0 -1
  100. package/dist/vitest.setup.d.ts +0 -1
  101. package/dist/vitest.setup.js +0 -22
  102. package/dist/vitest.setup.js.map +0 -1
  103. package/src/adapters/adapter.ts +0 -35
  104. package/src/adapters/botpress-table.ts +0 -213
  105. package/src/adapters/memory.ts +0 -13
  106. package/src/env.ts +0 -54
  107. package/src/index.ts +0 -11
  108. package/src/models.ts +0 -347
  109. package/src/operations/__tests/botpress_docs.txt +0 -26040
  110. package/src/operations/__tests/index.ts +0 -30
  111. package/src/operations/check.test.ts +0 -155
  112. package/src/operations/check.ts +0 -187
  113. package/src/operations/constants.ts +0 -2
  114. package/src/operations/errors.ts +0 -9
  115. package/src/operations/extract.test.ts +0 -209
  116. package/src/operations/extract.ts +0 -291
  117. package/src/operations/filter.test.ts +0 -182
  118. package/src/operations/filter.ts +0 -231
  119. package/src/operations/label.test.ts +0 -239
  120. package/src/operations/label.ts +0 -332
  121. package/src/operations/rewrite.test.ts +0 -114
  122. package/src/operations/rewrite.ts +0 -148
  123. package/src/operations/summarize.test.ts +0 -25
  124. package/src/operations/summarize.ts +0 -193
  125. package/src/operations/text.test.ts +0 -60
  126. package/src/operations/text.ts +0 -63
  127. package/src/operations/zai-learn.test.ts +0 -85
  128. package/src/operations/zai-retry.test.ts +0 -64
  129. package/src/scripts/update-models.ts +0 -74
  130. package/src/utils.ts +0 -61
  131. package/src/zai.ts +0 -185
  132. package/tsconfig.types.json +0 -22
  133. package/turbo.json +0 -14
@@ -1,96 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
2
- import { check } from '@botpress/vai';
3
- import { getClient, getZai, metadata, tokenizer } from './__tests';
4
- import { TableAdapter } from '../adapters/botpress-table';
5
- const Zoe = `
6
- Part 1. Zoe walks to the park.
7
- Part 2. She meets her friend.
8
- Part 3. They play together.
9
- Part 4. They have a picnic.
10
- Part 5. They go home.
11
- `.trim();
12
- describe('zai.rewrite', { timeout: 60_000 }, () => {
13
- const zai = getZai();
14
- it('transforms text to all caps', async () => {
15
- const result = await zai.rewrite(`Hello, what is the time today?`, 'write in all caps');
16
- expect(result).toBe(`HELLO, WHAT IS THE TIME TODAY?`);
17
- });
18
- it('transforms text to all caps and respects tokens restrictions', async () => {
19
- const result = await zai.rewrite(Zoe, 'write in all caps', { length: 15 });
20
- expect(tokenizer.count(result)).toBeLessThanOrEqual(20);
21
- expect(result).toContain(`PART 1. ZOE WALKS TO THE PARK`);
22
- expect(result).not.toContain(`PART 3`);
23
- });
24
- it('french translation of the story', async () => {
25
- const result = await zai.rewrite(Zoe, 'translate to french');
26
- check(result, 'is a french story about Zeo and with 5 parts').toBe(true);
27
- });
28
- it('Throws if input is bigger than the model max tokens', async () => {
29
- await expect(zai.rewrite(Zoe.repeat(100_000), 'translate to french')).rejects.toThrow(/tokens/i);
30
- });
31
- });
32
- describe('zai.learn.rewrite', { timeout: 60_000 }, () => {
33
- const client = getClient();
34
- let tableName = 'ZaiTestRewriteInternalTable';
35
- let taskId = 'rewrite';
36
- let zai = getZai();
37
- beforeEach(async () => {
38
- zai = getZai().with({
39
- activeLearning: {
40
- enable: true,
41
- taskId,
42
- tableName
43
- }
44
- });
45
- });
46
- afterEach(async () => {
47
- try {
48
- await client.deleteTableRows({ table: tableName, deleteAllRows: true });
49
- }
50
- catch (err) { }
51
- });
52
- afterAll(async () => {
53
- try {
54
- await client.deleteTable({ table: tableName });
55
- }
56
- catch (err) { }
57
- });
58
- it('learns rewrite rules from examples', async () => {
59
- const adapter = new TableAdapter({
60
- client,
61
- tableName
62
- });
63
- const value = await zai.learn(taskId).rewrite(`Botpress is awesome`, 'write it like we want it');
64
- check(value, `The text means more or less the same as "Botpress is awesome" but slightly different`).toBe(true);
65
- let rows = await client.findTableRows({ table: tableName });
66
- expect(rows.rows.length).toBe(1);
67
- expect(rows.rows[0].output.value).toBe(value);
68
- await adapter.saveExample({
69
- key: 't1',
70
- taskId: `zai/${taskId}`,
71
- taskType: 'zai.rewrite',
72
- instructions: 'write it like we want it',
73
- input: 'Microsoft is a big company',
74
- output: `# MICROSOFT IS A BIG COMPANY`,
75
- metadata,
76
- status: 'approved'
77
- });
78
- await adapter.saveExample({
79
- key: 't2',
80
- taskId: `zai/${taskId}`,
81
- taskType: 'zai.rewrite',
82
- instructions: 'write it like we want it',
83
- input: 'Google is an evil company',
84
- output: `# GOOGLE IS AN EVIL COMPANY`,
85
- metadata,
86
- status: 'approved'
87
- });
88
- const second = await zai.learn(taskId).rewrite(`Botpress is awesome`, 'write it like we want it');
89
- rows = await client.findTableRows({ table: tableName });
90
- expect(rows.rows.length).toBe(3);
91
- check(second, `The text is "BOTPRESS IS AWESOME" and starts with a hashtag`).toBe(true);
92
- expect(rows.rows.length).toBe(3);
93
- expect(rows.rows[0].output.value).toBe(second);
94
- });
95
- });
96
- //# sourceMappingURL=rewrite.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rewrite.test.js","sourceRoot":"","sources":["../../../src/operations/rewrite.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE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AC,MAAM,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,CAAA;QAEjG,IAAI,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;QACvD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAEhC,KAAK,CAAC,MAAM,EAAE,6DAA6D,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEvF,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,46 +0,0 @@
1
- import { z } from '@bpinternal/zui';
2
- export type Options = z.input<typeof Options>;
3
- declare const Options: import("@bpinternal/zui").ZodObject<{
4
- prompt: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodString>;
5
- format: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodString>;
6
- length: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
7
- intermediateFactor: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
8
- maxIterations: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodNumber>;
9
- sliding: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodObject<{
10
- window: import("@bpinternal/zui").ZodNumber;
11
- overlap: import("@bpinternal/zui").ZodNumber;
12
- }, "strip", import("@bpinternal/zui").ZodTypeAny, {
13
- window: number;
14
- overlap: number;
15
- }, {
16
- window: number;
17
- overlap: number;
18
- }>>;
19
- }, "strip", import("@bpinternal/zui").ZodTypeAny, {
20
- length: number;
21
- prompt: string;
22
- format: string;
23
- intermediateFactor: number;
24
- maxIterations: number;
25
- sliding: {
26
- window: number;
27
- overlap: number;
28
- };
29
- }, {
30
- length?: number | undefined;
31
- prompt?: string | undefined;
32
- format?: string | undefined;
33
- intermediateFactor?: number | undefined;
34
- maxIterations?: number | undefined;
35
- sliding?: {
36
- window: number;
37
- overlap: number;
38
- } | undefined;
39
- }>;
40
- declare module '../zai' {
41
- interface Zai {
42
- /** Summarizes a text of any length to a summary of the desired length */
43
- summarize(original: string, options?: Options): Promise<string>;
44
- }
45
- }
46
- export {};
@@ -1,139 +0,0 @@
1
- import { z } from '@bpinternal/zui';
2
- import _ from 'lodash';
3
- import { Zai } from '../zai';
4
- import { PROMPT_INPUT_BUFFER, PROMPT_OUTPUT_BUFFER } from './constants';
5
- const Options = z.object({
6
- prompt: z
7
- .string()
8
- .describe('What should the text be summarized to?')
9
- .default('New information, concepts and ideas that are deemed important'),
10
- format: z
11
- .string()
12
- .describe('How to format the example text')
13
- .default('A normal text with multiple sentences and paragraphs. Use markdown to format the text into sections. Use headings, lists, and other markdown features to make the text more readable. Do not include links, images, or other non-text elements.'),
14
- length: z.number().min(10).max(100_000).describe('The length of the summary in tokens').default(250),
15
- intermediateFactor: z
16
- .number()
17
- .min(1)
18
- .max(10)
19
- .describe('How many times longer (than final length) are the intermediate summaries generated')
20
- .default(4),
21
- maxIterations: z.number().min(1).default(100),
22
- sliding: z
23
- .object({
24
- window: z.number().min(10).max(100_000),
25
- overlap: z.number().min(0).max(100_000)
26
- })
27
- .describe('Sliding window options')
28
- .default({ window: 50_000, overlap: 250 })
29
- });
30
- const START = '■START■';
31
- const END = '■END■';
32
- Zai.prototype.summarize = async function (original, _options) {
33
- const options = Options.parse(_options ?? {});
34
- const tokenizer = await this.getTokenizer();
35
- const INPUT_COMPONENT_SIZE = Math.max(100, (this.Model.input.maxTokens - PROMPT_INPUT_BUFFER) / 4);
36
- options.prompt = tokenizer.truncate(options.prompt, INPUT_COMPONENT_SIZE);
37
- options.format = tokenizer.truncate(options.format, INPUT_COMPONENT_SIZE);
38
- const maxOutputSize = this.Model.output.maxTokens - PROMPT_OUTPUT_BUFFER;
39
- if (options.length > maxOutputSize) {
40
- throw new Error(`The desired output length is ${maxOutputSize} tokens long, which is more than the maximum of ${this.Model.output.maxTokens} tokens for this model (${this.Model.name})`);
41
- }
42
- // Ensure the sliding window is not bigger than the model input size
43
- options.sliding.window = Math.min(options.sliding.window, this.Model.input.maxTokens - PROMPT_INPUT_BUFFER);
44
- // Ensure the overlap is not bigger than the window
45
- // Most extreme case possible (all 3 same size)
46
- // |ooooooooooooooooooo|wwwwwwwwwwwwwww|ooooooooooooooooooo|
47
- // |<---- overlap ---->|<-- window -->|<---- overlap ---->|
48
- options.sliding.overlap = Math.min(options.sliding.overlap, options.sliding.window - 3 * options.sliding.overlap);
49
- const format = (summary, newText) => {
50
- return `
51
- ${START}
52
- ${summary.length ? summary : '<summary still empty>'}
53
- ${END}
54
-
55
- Please amend the summary between the ${START} and ${END} tags to accurately reflect the prompt and the additional text below.
56
-
57
- <|start_new_information|>
58
- ${newText}
59
- <|new_information|>`.trim();
60
- };
61
- const tokens = tokenizer.split(original);
62
- const parts = Math.ceil(tokens.length / (options.sliding.window - options.sliding.overlap));
63
- let iteration = 0;
64
- // We split it recursively into smaller parts until we're at less than 4 window slides per part
65
- // Then we use a merge strategy to combine the sub-chunks summaries
66
- // This is basically a merge sort algorithm (but summary instead of sorting)
67
- const N = 2; // This is the merge sort exponent
68
- const useMergeSort = parts >= Math.pow(2, N);
69
- const chunkSize = Math.ceil(tokens.length / (parts * N));
70
- if (useMergeSort) {
71
- const chunks = _.chunk(tokens, chunkSize).map((x) => x.join(''));
72
- const allSummaries = await Promise.all(chunks.map((chunk) => this.summarize(chunk, options)));
73
- return this.summarize(allSummaries.join('\n\n============\n\n'), options);
74
- }
75
- const summaries = [];
76
- let currentSummary = '';
77
- for (let i = 0; i < tokens.length; i += options.sliding.window) {
78
- const from = Math.max(0, i - options.sliding.overlap);
79
- const to = Math.min(tokens.length, i + options.sliding.window + options.sliding.overlap);
80
- const isFirst = i === 0;
81
- const isLast = to >= tokens.length;
82
- const slice = tokens.slice(from, to).join('');
83
- if (iteration++ >= options.maxIterations) {
84
- break;
85
- }
86
- const instructions = [
87
- `At each step, you will receive a part of the text to summarize. Make sure to reply with the new summary in the tags ${START} and ${END}.`,
88
- 'Summarize the text and make sure that the main points are included.',
89
- 'Ignore any unnecessary details and focus on the main points.',
90
- 'Use short and concise sentences to increase readability and information density.',
91
- 'When looking at the new information, focus on: ' + options.prompt
92
- ];
93
- if (isFirst) {
94
- instructions.push('The current summary is empty. You need to generate a summary that covers the main points of the text.');
95
- }
96
- let generationLength = options.length;
97
- if (!isLast) {
98
- generationLength = Math.min(tokenizer.count(currentSummary) + options.length * options.intermediateFactor, maxOutputSize);
99
- instructions.push('You need to amend the summary to include the new information. Make sure the summary is complete and covers all the main points.');
100
- instructions.push(`The current summary is ${currentSummary.length} tokens long.`);
101
- instructions.push(`You can amend the summary to be up to ${generationLength} tokens long.`);
102
- }
103
- if (isLast) {
104
- instructions.push('This is the last part you will have to summarize. Make sure the summary is complete and covers all the main points.');
105
- instructions.push(`The current summary is ${currentSummary.length} tokens long. You need to make sure it is ${options.length} tokens or less.`);
106
- if (currentSummary.length > options.length) {
107
- instructions.push(`The current summary is already too long, so you need to shorten it to ${options.length} tokens while also including the new information.`);
108
- }
109
- }
110
- const output = await this.callModel({
111
- systemPrompt: `
112
- You are summarizing a text. The text is split into ${parts} parts, and you are currently working on part ${iteration}.
113
- At every step, you will receive the current summary and a new part of the text. You need to amend the summary to include the new information (if needed).
114
- The summary needs to cover the main points of the text and must be concise.
115
-
116
- IMPORTANT INSTRUCTIONS:
117
- ${instructions.map((x) => `- ${x.trim()}`).join('\n')}
118
-
119
- FORMAT OF THE SUMMARY:
120
- ${options.format}
121
- `.trim(),
122
- messages: [{ type: 'text', content: format(currentSummary, slice), role: 'user' }],
123
- maxTokens: generationLength,
124
- stopSequences: [END]
125
- });
126
- let result = output.choices[0].content;
127
- if (result.includes(START)) {
128
- result = result.slice(result.indexOf(START) + START.length);
129
- }
130
- if (result.includes('■')) {
131
- // can happen if the model truncates the text before the entire END tag is written
132
- result = result.slice(0, result.indexOf('■'));
133
- }
134
- summaries.push(result);
135
- currentSummary = result;
136
- }
137
- return currentSummary.trim();
138
- };
139
- //# sourceMappingURL=summarize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../../src/operations/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AAEnC,OAAO,CAAC,MAAM,QAAQ,CAAA;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAGvE,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IACvB,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,QAAQ,CAAC,wCAAwC,CAAC;SAClD,OAAO,CAAC,+DAA+D,CAAC;IAC3E,MAAM,EAAE,CAAC;SACN,MAAM,EAAE;SACR,QAAQ,CAAC,gCAAgC,CAAC;SAC1C,OAAO,CACN,iPAAiP,CAClP;IACH,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,qCAAqC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IACpG,kBAAkB,EAAE,CAAC;SAClB,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,EAAE,CAAC;SACP,QAAQ,CAAC,oFAAoF,CAAC;SAC9F,OAAO,CAAC,CAAC,CAAC;IACb,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CA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ocumentation, getZai } from './__tests';
4
- describe('zai.summarize', () => {
5
- const zai = getZai();
6
- it.skip('summarize long document to a concise 2000 token summary', async () => {
7
- const result = await zai.summarize(BotpressDocumentation, {
8
- length: 2000,
9
- prompt: `Extract the Table of Contents for the Botpress Documentation. Pay special attention to all the different features. Focus on horizontal coverage of features rather than going in depth into one feature. The goal is to have a complete overview of what the documentation covers.`
10
- });
11
- check(result, 'The text is a summary of the Botpress documentation').toBe(true);
12
- check(result, 'The text explains shortly what botpress is').toBe(true);
13
- check(result, 'The text uses markdown format').toBe(true);
14
- check(result, 'The text has some information about integrations').toBe(true);
15
- check(result, 'The text has a section about Flows (or Workflows)').toBe(true);
16
- check(result, 'The text has a section about the Botpress API').toBe(true);
17
- check(result, 'The text mentions the notion of workspaces').toBe(true);
18
- check(result, 'The text has some information about the Webchat').toBe(true);
19
- check(result, 'The text has some information about HITL (human in the loop)').toBe(true);
20
- });
21
- });
22
- //# sourceMappingURL=summarize.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarize.test.js","sourceRoot":"","sources":["../../../src/operations/summarize.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEzD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAEpB,EAAE,CAAC,IAAI,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QAC5E,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE;YACxD,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,oRAAoR;SAC7R,CAAC,CAAA;QAEF,KAAK,CAAC,MAAM,EAAE,qDAAqD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC/E,KAAK,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtE,KAAK,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzD,KAAK,CAAC,MAAM,EAAE,kDAAkD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC5E,KAAK,CAAC,MAAM,EAAE,mDAAmD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC7E,KAAK,CAAC,MAAM,EAAE,+CAA+C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzE,KAAK,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtE,KAAK,CAAC,MAAM,EAAE,iDAAiD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC3E,KAAK,CAAC,MAAM,EAAE,8DAA8D,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1F,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,16 +0,0 @@
1
- import { z } from '@bpinternal/zui';
2
- export type Options = z.input<typeof Options>;
3
- declare const Options: import("@bpinternal/zui").ZodObject<{
4
- length: import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodNumber>;
5
- }, "strip", import("@bpinternal/zui").ZodTypeAny, {
6
- length?: number | undefined;
7
- }, {
8
- length?: number | undefined;
9
- }>;
10
- declare module '../zai' {
11
- interface Zai {
12
- /** Generates a text of the desired length according to the prompt */
13
- text(prompt: string, options?: Options): Promise<string>;
14
- }
15
- }
16
- export {};
@@ -1,47 +0,0 @@
1
- import { z } from '@bpinternal/zui';
2
- import _ from 'lodash';
3
- import { Zai } from '../zai';
4
- import { PROMPT_INPUT_BUFFER, PROMPT_OUTPUT_BUFFER } from './constants';
5
- const Options = z.object({
6
- length: z.number().min(1).max(100_000).optional().describe('The maximum number of tokens to generate')
7
- });
8
- Zai.prototype.text = async function (prompt, _options) {
9
- const options = Options.parse(_options ?? {});
10
- const tokenizer = await this.getTokenizer();
11
- prompt = tokenizer.truncate(prompt, Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100));
12
- if (options.length) {
13
- options.length = Math.min(this.Model.output.maxTokens - PROMPT_OUTPUT_BUFFER, options.length);
14
- }
15
- const instructions = [];
16
- let chart = '';
17
- if (options.length) {
18
- const length = _.clamp(options.length * 0.75, 5, options.length);
19
- instructions.push(`IMPORTANT: Length constraint: ${length} tokens/words`);
20
- instructions.push(`The text must be standalone and complete in less than ${length} tokens/words`);
21
- }
22
- if (options.length && options.length <= 500) {
23
- chart = `
24
- | Tokens | Text Length (approximate) |
25
- |-------------|--------------------------------------|
26
- | < 5 tokens | 1-3 words |
27
- | 5-10 tokens | 3-6 words |
28
- | 10-20 tokens| 6-15 words |
29
- | 20-50 tokens| A short sentence (15-30 words) |
30
- | 50-100 tokens| A medium sentence (30-70 words) |
31
- | 100-200 tokens| A short paragraph (70-150 words) |
32
- | 200-300 tokens| A medium paragraph (150-200 words) |
33
- | 300-500 tokens| A long paragraph (200-300 words) |`.trim();
34
- }
35
- const output = await this.callModel({
36
- systemPrompt: `
37
- Generate a text that fulfills the user prompt below. Answer directly to the prompt, without any acknowledgements or fluff. Also, make sure the text is standalone and complete.
38
- ${instructions.map((x) => `- ${x}`).join('\n')}
39
- ${chart}
40
- `.trim(),
41
- temperature: 0.7,
42
- messages: [{ type: 'text', content: prompt, role: 'user' }],
43
- maxTokens: options.length
44
- });
45
- return output.choices[0].content;
46
- };
47
- //# sourceMappingURL=text.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/operations/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AAEnC,OAAO,CAAC,MAAM,QAAQ,CAAA;AACtB,OAAO,EAAE,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CAAC,yDAAyD,MAAM,eAAe,CAAC,CAAA;IACnG,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;QAC5C,KAAK,GAAG;;;;;;;;;;uDAU2C,CAAC,IAAI,EAAE,CAAA;IAC5D,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC;QAClC,YAAY,EAAE;;EAEhB,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;EAC5C,KAAK;CACN,CAAC,IAAI,EAAE;QACJ,WAAW,EAAE,GAAG;QAChB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3D,SAAS,EAAE,OAAO,CAAC,MAAM;KAC1B,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAiB,CAAA;AAC5C,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,51 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { check } from '@botpress/vai';
3
- import { getZai, tokenizer } from './__tests';
4
- describe('zai.text', { timeout: 60_000 }, () => {
5
- const zai = getZai();
6
- it('generate a horror novel with no params', async () => {
7
- const story = await zai.text('write a short horror novel');
8
- check(story, 'is a short horror story').toBe(true);
9
- });
10
- it('No fluffy text at the beginning', async () => {
11
- const story = await zai.text('write a short horror novel');
12
- check(story, 'There is no LLM fluff at the beginning', {
13
- examples: [
14
- {
15
- value: 'Title: A horror story\nChapter 1: The woods\nOnce upen a time, ...',
16
- expected: true,
17
- reason: 'It begins straight with a story, no fluff at the beginning'
18
- },
19
- { value: 'Once upon a time, a ...', expected: true, reason: 'The story starts directly' },
20
- {
21
- value: 'Sure, I will generate a story.\nOnce upen a time, a...',
22
- expected: false,
23
- reason: 'There is some fluff at the beginning'
24
- }
25
- ]
26
- }).toBe(true);
27
- });
28
- it('No fluffy text at the end', async () => {
29
- const story = await zai.text('write a short horror novel');
30
- check(story, 'There is no LLM fluff at the end', {
31
- examples: [
32
- {
33
- value: 'Title: A horror story\nChapter 1: The woods\nOnce upen a time, ... The End.',
34
- expected: true,
35
- reason: 'The end is clear and direct, no fluff at the end'
36
- },
37
- {
38
- value: 'Sure, I will generate a story.\nOnce upen a time, a... The End.\nLet me know if you want more or if you are happy with this.',
39
- expected: false,
40
- reason: 'There is some fluff from the assistant at the end.'
41
- }
42
- ]
43
- }).toBe(true);
44
- });
45
- it('length/max tokens param', async () => {
46
- const story = await zai.text('write a short but complete horror story (with conclusion)', { length: 100 });
47
- expect(tokenizer.count(story)).toBeLessThanOrEqual(110);
48
- check(story, 'could be the beginning of a horror story').toBe(true);
49
- });
50
- });
51
- //# sourceMappingURL=text.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.test.js","sourceRoot":"","sources":["../../../src/operations/text.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAErC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE7C,QAAQ,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE;IAC7C,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAEpB,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;QACtD,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;QAC1D,KAAK,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC,CAAC,CAAA;IAEF,EAA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GAAG,CAAC,CAAA;QAEvD,KAAK,CAAC,KAAK,EAAE,0CAA0C,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,71 +0,0 @@
1
- import { describe, it, expect, afterAll, beforeEach, afterEach, vi } from 'vitest';
2
- import { getClient, getZai } from './__tests';
3
- import { check } from '@botpress/vai';
4
- describe('zai.learn / generic', { timeout: 60_000 }, () => {
5
- const client = getClient();
6
- let tableName = 'ZaiTestInternalTable';
7
- let taskId = 'test';
8
- let zai = getZai();
9
- beforeEach(async () => {
10
- zai = getZai().with({
11
- activeLearning: {
12
- enable: true,
13
- taskId,
14
- tableName
15
- }
16
- });
17
- });
18
- afterEach(async () => {
19
- try {
20
- await client.deleteTableRows({ table: tableName, deleteAllRows: true });
21
- }
22
- catch (err) { }
23
- });
24
- afterAll(async () => {
25
- try {
26
- await client.deleteTable({ table: tableName });
27
- }
28
- catch (err) { }
29
- });
30
- it('saves examples to tables', async () => {
31
- const value = await zai
32
- .learn(taskId)
33
- .check('This text is very clearly written in English.', 'is an english sentence');
34
- const { rows } = await client.findTableRows({ table: tableName });
35
- expect(value).toBe(true);
36
- expect(rows.length).toBe(1);
37
- check(rows[0].explanation, 'is an explanation sentence');
38
- expect(rows[0].explanation).not.toContain('Final Answer:');
39
- expect(rows[0].output).toMatchObject({ value: true });
40
- expect(rows[0].input).toMatchInlineSnapshot(`
41
- {
42
- "value": "This text is very clearly written in English.",
43
- }
44
- `);
45
- expect(rows[0].taskId).toEqual('zai/test');
46
- expect(rows[0].taskType).toBe('zai.check');
47
- });
48
- it('works even if tables are down', async () => {
49
- const upsertTableRows = vi.fn(async () => {
50
- throw new Error('Table is down');
51
- });
52
- const findTableRows = vi.fn(async () => {
53
- throw new Error('Table is down');
54
- });
55
- const client = {
56
- ...getClient(),
57
- findTableRows,
58
- upsertTableRows
59
- };
60
- const value = await zai
61
- .with({ client })
62
- .learn(taskId)
63
- .check('This text is very clearly written in English.', 'is an english sentence');
64
- const { rows } = await getClient().findTableRows({ table: tableName });
65
- expect(value).toBe(true);
66
- expect(rows.length).toBe(0);
67
- expect(upsertTableRows).toHaveBeenCalledTimes(1);
68
- expect(findTableRows).toHaveBeenCalledTimes(1);
69
- });
70
- });
71
- //# sourceMappingURL=zai-learn.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zai-learn.test.js","sourceRoot":"","sources":["../../../src/operations/zai-learn.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAElF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAGrC,QAAQ,CAAC,qBAAqB,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE;IACxD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,IAAI,SAAS,GAAG,sBAAsB,CAAA;IACtC,IAAI,MAAM,GAAG,MAAM,CAAA;IACnB,IAAI,GAAG,GAAG,MAAM,EAAE,CAAA;IAElB,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC;YAClB,cAAc,EAAE;gBACd,MAAM,EAAE,IAAI;gBACZ,MAAM;gBACN,SAAS;aACV;SACF,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;QACzE,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC,CAAA,CAAC;IA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C,IAAI,CAAC,WAAW,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,+BAA+B,EAAE,KAAK,IAAI,EAAE;QAC7C,MAAM,eAAe,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,MAAM,aAAa,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE;YACrC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAA;QAClC,CAAC,CAAC,CAAA;QAEF,MAAM,MAAM,GAAG;YACb,GAAG,SAAS,EAAE;YACd,aAAa;YACb,eAAe;SACK,CAAA;QAEtB,MAAM,KAAK,GAAG,MAAM,GAAG;aACpB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;aAChB,KAAK,CAAC,MAAM,CAAC;aACb,KAAK,CAAC,+CAA+C,EAAE,wBAAwB,CAAC,CAAA;QAEnF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,EAAE,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;QAEtE,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACxB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QAC3B,MAAM,CAAC,eAAe,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QAChD,MAAM,CAAC,aAAa,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,50 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { getClient, getZai } from './__tests';
3
- describe('zai retry', { timeout: 60_000 }, () => {
4
- const client = getClient();
5
- let zai = getZai().with({ retry: { maxRetries: 3 } });
6
- it('retries 3 times and succeeds', async () => {
7
- let retryCount = 0;
8
- const throwingClient = {
9
- ...client,
10
- callAction: vi.fn((input) => {
11
- if (++retryCount < 3) {
12
- throw new Error('Failed to call model');
13
- }
14
- return client.callAction(input);
15
- })
16
- };
17
- const value = await zai
18
- .with({ client: throwingClient })
19
- .check('This text is very clearly written in English.', 'is an english sentence');
20
- expect(value).toBe(true);
21
- expect(retryCount).toBe(3);
22
- });
23
- it('retries 0 times when success', async () => {
24
- const fn = vi.fn((input) => client.callAction(input));
25
- const throwingClient = {
26
- ...client,
27
- callAction: fn
28
- };
29
- const value = await zai
30
- .with({ client: throwingClient })
31
- .check('This text is very clearly written in English.', 'is an english sentence');
32
- expect(value).toBe(true);
33
- expect(fn).toHaveBeenCalledOnce();
34
- });
35
- it('fails when exceeded max', async () => {
36
- const fn = vi.fn(() => {
37
- throw new Error('Failed to call model');
38
- });
39
- const throwingClient = {
40
- ...client,
41
- callAction: fn
42
- };
43
- const value = zai
44
- .with({ client: throwingClient, retry: { maxRetries: 1 } })
45
- .check('This text is very clearly written in English.', 'is an english sentence');
46
- await expect(value).rejects.toThrowError(/retries/);
47
- expect(fn).toHaveBeenCalledTimes(2);
48
- });
49
- });
50
- //# sourceMappingURL=zai-retry.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zai-retry.test.js","sourceRoot":"","sources":["../../../src/operations/zai-retry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAI7C,QAAQ,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE;IAC9C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,IAAI,GAAG,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,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