@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.
- package/dist/index.cjs +1898 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +916 -0
- package/dist/index.d.ts +916 -0
- package/dist/index.js +1868 -0
- package/dist/index.js.map +1 -0
- package/ensure-env.cjs +9 -0
- package/package.json +25 -17
- package/tsconfig.json +23 -18
- package/tsup.config.ts +16 -0
- package/vitest.config.ts +2 -16
- package/vitest.setup.ts +11 -15
- package/dist/src/adapters/adapter.d.ts +0 -27
- package/dist/src/adapters/adapter.js +0 -3
- package/dist/src/adapters/adapter.js.map +0 -1
- package/dist/src/adapters/botpress-table.d.ts +0 -155
- package/dist/src/adapters/botpress-table.js +0 -170
- package/dist/src/adapters/botpress-table.js.map +0 -1
- package/dist/src/adapters/memory.d.ts +0 -7
- package/dist/src/adapters/memory.js +0 -13
- package/dist/src/adapters/memory.js.map +0 -1
- package/dist/src/env.d.ts +0 -1
- package/dist/src/env.js +0 -27
- package/dist/src/env.js.map +0 -1
- package/dist/src/index.d.ts +0 -9
- package/dist/src/index.js +0 -10
- package/dist/src/index.js.map +0 -1
- package/dist/src/models.d.ts +0 -253
- package/dist/src/models.js +0 -348
- package/dist/src/models.js.map +0 -1
- package/dist/src/operations/__tests/index.d.ts +0 -19
- package/dist/src/operations/__tests/index.js +0 -24
- package/dist/src/operations/__tests/index.js.map +0 -1
- package/dist/src/operations/check.d.ts +0 -36
- package/dist/src/operations/check.js +0 -146
- package/dist/src/operations/check.js.map +0 -1
- package/dist/src/operations/check.test.d.ts +0 -1
- package/dist/src/operations/check.test.js +0 -129
- package/dist/src/operations/check.test.js.map +0 -1
- package/dist/src/operations/constants.d.ts +0 -2
- package/dist/src/operations/constants.js +0 -3
- package/dist/src/operations/constants.js.map +0 -1
- package/dist/src/operations/errors.d.ts +0 -5
- package/dist/src/operations/errors.js +0 -11
- package/dist/src/operations/errors.js.map +0 -1
- package/dist/src/operations/extract.d.ts +0 -20
- package/dist/src/operations/extract.js +0 -235
- package/dist/src/operations/extract.js.map +0 -1
- package/dist/src/operations/extract.test.d.ts +0 -1
- package/dist/src/operations/extract.test.js +0 -163
- package/dist/src/operations/extract.test.js.map +0 -1
- package/dist/src/operations/filter.d.ts +0 -39
- package/dist/src/operations/filter.js +0 -184
- package/dist/src/operations/filter.js.map +0 -1
- package/dist/src/operations/filter.test.d.ts +0 -1
- package/dist/src/operations/filter.test.js +0 -151
- package/dist/src/operations/filter.test.js.map +0 -1
- package/dist/src/operations/label.d.ts +0 -79
- package/dist/src/operations/label.js +0 -250
- package/dist/src/operations/label.js.map +0 -1
- package/dist/src/operations/label.test.d.ts +0 -1
- package/dist/src/operations/label.test.js +0 -213
- package/dist/src/operations/label.test.js.map +0 -1
- package/dist/src/operations/rewrite.d.ts +0 -34
- package/dist/src/operations/rewrite.js +0 -106
- package/dist/src/operations/rewrite.js.map +0 -1
- package/dist/src/operations/rewrite.test.d.ts +0 -1
- package/dist/src/operations/rewrite.test.js +0 -96
- package/dist/src/operations/rewrite.test.js.map +0 -1
- package/dist/src/operations/summarize.d.ts +0 -46
- package/dist/src/operations/summarize.js +0 -139
- package/dist/src/operations/summarize.js.map +0 -1
- package/dist/src/operations/summarize.test.d.ts +0 -1
- package/dist/src/operations/summarize.test.js +0 -22
- package/dist/src/operations/summarize.test.js.map +0 -1
- package/dist/src/operations/text.d.ts +0 -16
- package/dist/src/operations/text.js +0 -47
- package/dist/src/operations/text.js.map +0 -1
- package/dist/src/operations/text.test.d.ts +0 -1
- package/dist/src/operations/text.test.js +0 -51
- package/dist/src/operations/text.test.js.map +0 -1
- package/dist/src/operations/zai-learn.test.d.ts +0 -1
- package/dist/src/operations/zai-learn.test.js +0 -71
- package/dist/src/operations/zai-learn.test.js.map +0 -1
- package/dist/src/operations/zai-retry.test.d.ts +0 -1
- package/dist/src/operations/zai-retry.test.js +0 -50
- package/dist/src/operations/zai-retry.test.js.map +0 -1
- package/dist/src/utils.d.ts +0 -53
- package/dist/src/utils.js +0 -49
- package/dist/src/utils.js.map +0 -1
- package/dist/src/zai.d.ts +0 -91
- package/dist/src/zai.js +0 -139
- package/dist/src/zai.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/typings.d.ts +0 -901
- package/dist/typings.tsbuildinfo +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -21
- package/dist/vitest.config.js.map +0 -1
- package/dist/vitest.setup.d.ts +0 -1
- package/dist/vitest.setup.js +0 -22
- package/dist/vitest.setup.js.map +0 -1
- package/src/adapters/adapter.ts +0 -35
- package/src/adapters/botpress-table.ts +0 -213
- package/src/adapters/memory.ts +0 -13
- package/src/env.ts +0 -54
- package/src/index.ts +0 -11
- package/src/models.ts +0 -347
- package/src/operations/__tests/botpress_docs.txt +0 -26040
- package/src/operations/__tests/index.ts +0 -30
- package/src/operations/check.test.ts +0 -155
- package/src/operations/check.ts +0 -187
- package/src/operations/constants.ts +0 -2
- package/src/operations/errors.ts +0 -9
- package/src/operations/extract.test.ts +0 -209
- package/src/operations/extract.ts +0 -291
- package/src/operations/filter.test.ts +0 -182
- package/src/operations/filter.ts +0 -231
- package/src/operations/label.test.ts +0 -239
- package/src/operations/label.ts +0 -332
- package/src/operations/rewrite.test.ts +0 -114
- package/src/operations/rewrite.ts +0 -148
- package/src/operations/summarize.test.ts +0 -25
- package/src/operations/summarize.ts +0 -193
- package/src/operations/text.test.ts +0 -60
- package/src/operations/text.ts +0 -63
- package/src/operations/zai-learn.test.ts +0 -85
- package/src/operations/zai-retry.test.ts +0 -64
- package/src/scripts/update-models.ts +0 -74
- package/src/utils.ts +0 -61
- package/src/zai.ts +0 -185
- package/tsconfig.types.json +0 -22
- package/turbo.json +0 -14
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
|
|
2
|
-
import { BotpressDocumentation, getClient, getZai, metadata } from './__tests';
|
|
3
|
-
import { z } from '@bpinternal/zui';
|
|
4
|
-
import { check } from '@botpress/vai';
|
|
5
|
-
import { TableAdapter } from '../adapters/botpress-table';
|
|
6
|
-
describe('zai.extract', () => {
|
|
7
|
-
const zai = getZai();
|
|
8
|
-
it('extract simple object from paragraph', async () => {
|
|
9
|
-
const person = await zai.extract('My name is John Doe, I am 30 years old and I live in Quebec', z.object({
|
|
10
|
-
name: z.string(),
|
|
11
|
-
age: z.number(),
|
|
12
|
-
location: z.string()
|
|
13
|
-
}));
|
|
14
|
-
expect(person).toMatchInlineSnapshot(`
|
|
15
|
-
{
|
|
16
|
-
"age": 30,
|
|
17
|
-
"location": "Quebec",
|
|
18
|
-
"name": "John Doe",
|
|
19
|
-
}
|
|
20
|
-
`);
|
|
21
|
-
});
|
|
22
|
-
it('extract an array of objects from paragraph', async () => {
|
|
23
|
-
const people = await zai.extract(`
|
|
24
|
-
My name is John Doe, I am 30 years old and I live in Quebec.
|
|
25
|
-
My name is Jane Doe, I am 25 years old and I live in Montreal.
|
|
26
|
-
His name is Jack Doe, he is 35 years old and he lives in Toronto.
|
|
27
|
-
Her name is Jill Doe, she is 40 years old and she lives in Vancouver.`, z.array(z.object({
|
|
28
|
-
name: z.string(),
|
|
29
|
-
age: z.number(),
|
|
30
|
-
location: z.string()
|
|
31
|
-
})));
|
|
32
|
-
expect(people).toMatchInlineSnapshot(`
|
|
33
|
-
[
|
|
34
|
-
{
|
|
35
|
-
"age": 30,
|
|
36
|
-
"location": "Quebec",
|
|
37
|
-
"name": "John Doe",
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"age": 25,
|
|
41
|
-
"location": "Montreal",
|
|
42
|
-
"name": "Jane Doe",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"age": 35,
|
|
46
|
-
"location": "Toronto",
|
|
47
|
-
"name": "Jack Doe",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
"age": 40,
|
|
51
|
-
"location": "Vancouver",
|
|
52
|
-
"name": "Jill Doe",
|
|
53
|
-
},
|
|
54
|
-
]
|
|
55
|
-
`);
|
|
56
|
-
});
|
|
57
|
-
it('extract an object from anything as input', async () => {
|
|
58
|
-
const person = await zai.extract({
|
|
59
|
-
person: { first: 'John', last: 'Doe', age: 30 }
|
|
60
|
-
}, z.object({
|
|
61
|
-
a: z.string().describe('The full name of the person in the text'),
|
|
62
|
-
b: z.number().describe('The age of the person in the text')
|
|
63
|
-
}));
|
|
64
|
-
expect(person).toMatchInlineSnapshot(`
|
|
65
|
-
{
|
|
66
|
-
"a": "John Doe",
|
|
67
|
-
"b": 30,
|
|
68
|
-
}
|
|
69
|
-
`);
|
|
70
|
-
});
|
|
71
|
-
it('extract an array of objects from a super long text', async () => {
|
|
72
|
-
const features = await zai.extract(BotpressDocumentation, z.array(z
|
|
73
|
-
.object({
|
|
74
|
-
feature: z.string().describe('The name of the feature'),
|
|
75
|
-
parent: z.string().optional().describe('The parent feature').nullable(),
|
|
76
|
-
description: z.string().describe('The description of the feature')
|
|
77
|
-
})
|
|
78
|
-
.describe('A feature of Botpress')), {
|
|
79
|
-
instructions: 'Extract all things that looks like a Botpress feature in the provided input. You must extract a minimum of one element.'
|
|
80
|
-
});
|
|
81
|
-
check(features, 'Contains an element about flows / workflows').toBe(true);
|
|
82
|
-
check(features, 'Contains an element about tables').toBe(true);
|
|
83
|
-
check(features, 'Contains an element about webchat').toBe(true);
|
|
84
|
-
check(features, 'Contains an element about integrations').toBe(true);
|
|
85
|
-
check(features, 'Contains an element about HITL (human in the loop)').toBe(true);
|
|
86
|
-
check(features, 'Contains an element about knowledge bases (KB) or Files API').toBe(true);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('zai.learn.extract', () => {
|
|
90
|
-
const client = getClient();
|
|
91
|
-
let tableName = 'ZaiTestExtractInternalTable';
|
|
92
|
-
let taskId = 'extract';
|
|
93
|
-
let zai = getZai();
|
|
94
|
-
beforeEach(async () => {
|
|
95
|
-
zai = getZai().with({
|
|
96
|
-
activeLearning: {
|
|
97
|
-
enable: true,
|
|
98
|
-
taskId,
|
|
99
|
-
tableName
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
afterEach(async () => {
|
|
104
|
-
try {
|
|
105
|
-
await client.deleteTableRows({ table: tableName, deleteAllRows: true });
|
|
106
|
-
}
|
|
107
|
-
catch (err) { }
|
|
108
|
-
});
|
|
109
|
-
afterAll(async () => {
|
|
110
|
-
try {
|
|
111
|
-
await client.deleteTable({ table: tableName });
|
|
112
|
-
}
|
|
113
|
-
catch (err) { }
|
|
114
|
-
});
|
|
115
|
-
it('learns a extraction format from examples', async () => {
|
|
116
|
-
const adapter = new TableAdapter({
|
|
117
|
-
client,
|
|
118
|
-
tableName
|
|
119
|
-
});
|
|
120
|
-
const value = await zai.learn(taskId).extract(`I really liked Casino Royale`, z.object({
|
|
121
|
-
name: z.string(),
|
|
122
|
-
movie: z.string()
|
|
123
|
-
}), { instructions: 'extract the name of the movie and name of the main character' });
|
|
124
|
-
check(value, 'extracted james bond and casino royale').toBe(true);
|
|
125
|
-
check(value, 'the values are NOT IN ALL CAPS').toBe(true);
|
|
126
|
-
let rows = await client.findTableRows({ table: tableName });
|
|
127
|
-
expect(rows.rows.length).toBe(1);
|
|
128
|
-
await adapter.saveExample({
|
|
129
|
-
key: 't1',
|
|
130
|
-
taskId: `zai/${taskId}`,
|
|
131
|
-
taskType: 'zai.extract',
|
|
132
|
-
instructions: 'extract name of movie and main character',
|
|
133
|
-
input: `I went to see the Titanic yesterday and I fell asleep`,
|
|
134
|
-
output: { name: 'JACK DAWSON', movie: 'TITANIC' },
|
|
135
|
-
metadata,
|
|
136
|
-
status: 'approved'
|
|
137
|
-
});
|
|
138
|
-
await adapter.saveExample({
|
|
139
|
-
key: 't2',
|
|
140
|
-
taskId: `zai/${taskId}`,
|
|
141
|
-
taskType: 'zai.extract',
|
|
142
|
-
instructions: 'extract name of movie and main character',
|
|
143
|
-
input: `Did you know that the gladiator movie has a lot of fighting scenes?`,
|
|
144
|
-
output: { name: 'MAXIMUS DECIMUS MERIDIUS', movie: 'GLADIATOR' },
|
|
145
|
-
metadata,
|
|
146
|
-
status: 'approved'
|
|
147
|
-
});
|
|
148
|
-
const second = await zai.learn(taskId).extract(`I really liked Casino Royale`, z.object({
|
|
149
|
-
name: z.string(),
|
|
150
|
-
movie: z.string()
|
|
151
|
-
}), { instructions: 'extract the name of the movie and name of the main character' });
|
|
152
|
-
expect(second).toMatchInlineSnapshot(`
|
|
153
|
-
{
|
|
154
|
-
"movie": "CASINO ROYALE",
|
|
155
|
-
"name": "JAMES BOND",
|
|
156
|
-
}
|
|
157
|
-
`);
|
|
158
|
-
rows = await client.findTableRows({ table: tableName });
|
|
159
|
-
expect(rows.rows.length).toBe(3);
|
|
160
|
-
expect(rows.rows[0].output.value).toMatchObject(second);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
//# sourceMappingURL=extract.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extract.test.js","sourceRoot":"","sources":["../../../src/operations/extract.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAE9E,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC9E,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAEzD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IAEpB,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,E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,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;QAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;IACzD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,39 +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
|
-
tokensPerItem: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodNumber>>;
|
|
5
|
-
examples: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodArray<import("@bpinternal/zui").ZodObject<{
|
|
6
|
-
input: import("@bpinternal/zui").ZodAny;
|
|
7
|
-
filter: import("@bpinternal/zui").ZodBoolean;
|
|
8
|
-
reason: import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodString>;
|
|
9
|
-
}, "strip", import("@bpinternal/zui").ZodTypeAny, {
|
|
10
|
-
filter: boolean;
|
|
11
|
-
input?: any;
|
|
12
|
-
reason?: string | undefined;
|
|
13
|
-
}, {
|
|
14
|
-
filter: boolean;
|
|
15
|
-
input?: any;
|
|
16
|
-
reason?: string | undefined;
|
|
17
|
-
}>, "many">>;
|
|
18
|
-
}, "strip", import("@bpinternal/zui").ZodTypeAny, {
|
|
19
|
-
examples: {
|
|
20
|
-
filter: boolean;
|
|
21
|
-
input?: any;
|
|
22
|
-
reason?: string | undefined;
|
|
23
|
-
}[];
|
|
24
|
-
tokensPerItem: number;
|
|
25
|
-
}, {
|
|
26
|
-
examples?: {
|
|
27
|
-
filter: boolean;
|
|
28
|
-
input?: any;
|
|
29
|
-
reason?: string | undefined;
|
|
30
|
-
}[] | undefined;
|
|
31
|
-
tokensPerItem?: number | undefined;
|
|
32
|
-
}>;
|
|
33
|
-
declare module '../zai' {
|
|
34
|
-
interface Zai {
|
|
35
|
-
/** Filters elements of an array against a condition */
|
|
36
|
-
filter<T>(input: Array<T>, condition: string, options?: Options): Promise<Array<T>>;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
export {};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { z } from '@bpinternal/zui';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { fastHash, stringify, takeUntilTokens } from '../utils';
|
|
4
|
-
import { Zai } from '../zai';
|
|
5
|
-
import { PROMPT_INPUT_BUFFER, PROMPT_OUTPUT_BUFFER } from './constants';
|
|
6
|
-
const Example = z.object({
|
|
7
|
-
input: z.any(),
|
|
8
|
-
filter: z.boolean(),
|
|
9
|
-
reason: z.string().optional()
|
|
10
|
-
});
|
|
11
|
-
const Options = z.object({
|
|
12
|
-
tokensPerItem: z
|
|
13
|
-
.number()
|
|
14
|
-
.min(1)
|
|
15
|
-
.max(100_000)
|
|
16
|
-
.optional()
|
|
17
|
-
.describe('The maximum number of tokens per item')
|
|
18
|
-
.default(250),
|
|
19
|
-
examples: z.array(Example).describe('Examples to filter the condition against').default([])
|
|
20
|
-
});
|
|
21
|
-
const END = '■END■';
|
|
22
|
-
Zai.prototype.filter = async function (input, condition, _options) {
|
|
23
|
-
const options = Options.parse(_options ?? {});
|
|
24
|
-
const tokenizer = await this.getTokenizer();
|
|
25
|
-
const taskId = this.taskId;
|
|
26
|
-
const taskType = 'zai.filter';
|
|
27
|
-
const MAX_ITEMS_PER_CHUNK = 50;
|
|
28
|
-
const TOKENS_TOTAL_MAX = this.Model.input.maxTokens - PROMPT_INPUT_BUFFER - PROMPT_OUTPUT_BUFFER;
|
|
29
|
-
const TOKENS_EXAMPLES_MAX = Math.floor(Math.max(250, TOKENS_TOTAL_MAX * 0.5));
|
|
30
|
-
const TOKENS_CONDITION_MAX = _.clamp(TOKENS_TOTAL_MAX * 0.25, 250, tokenizer.count(condition));
|
|
31
|
-
const TOKENS_INPUT_ARRAY_MAX = TOKENS_TOTAL_MAX - TOKENS_EXAMPLES_MAX - TOKENS_CONDITION_MAX;
|
|
32
|
-
condition = tokenizer.truncate(condition, TOKENS_CONDITION_MAX);
|
|
33
|
-
let chunks = [];
|
|
34
|
-
let currentChunk = [];
|
|
35
|
-
let currentChunkTokens = 0;
|
|
36
|
-
for (const element of input) {
|
|
37
|
-
const elementAsString = tokenizer.truncate(stringify(element, false), options.tokensPerItem);
|
|
38
|
-
const elementTokens = tokenizer.count(elementAsString);
|
|
39
|
-
if (currentChunkTokens + elementTokens > TOKENS_INPUT_ARRAY_MAX || currentChunk.length >= MAX_ITEMS_PER_CHUNK) {
|
|
40
|
-
chunks.push(currentChunk);
|
|
41
|
-
currentChunk = [];
|
|
42
|
-
currentChunkTokens = 0;
|
|
43
|
-
}
|
|
44
|
-
currentChunk.push(element);
|
|
45
|
-
currentChunkTokens += elementTokens;
|
|
46
|
-
}
|
|
47
|
-
if (currentChunk.length > 0) {
|
|
48
|
-
chunks.push(currentChunk);
|
|
49
|
-
}
|
|
50
|
-
chunks = chunks.filter((x) => x.length > 0);
|
|
51
|
-
// ■1:true■2:true■3:true
|
|
52
|
-
const formatInput = (input, condition) => {
|
|
53
|
-
return `
|
|
54
|
-
Condition to check:
|
|
55
|
-
${condition}
|
|
56
|
-
|
|
57
|
-
Items (from ■0 to ■${input.length - 1})
|
|
58
|
-
==============================
|
|
59
|
-
${input.map((x, idx) => `■${idx} = ${stringify(x.input ?? null, false)}`).join('\n')}
|
|
60
|
-
`.trim();
|
|
61
|
-
};
|
|
62
|
-
const formatExamples = (examples) => {
|
|
63
|
-
return `
|
|
64
|
-
${examples.map((x, idx) => `■${idx}:${!!x.filter ? 'true' : 'false'}`).join('')}
|
|
65
|
-
${END}
|
|
66
|
-
====
|
|
67
|
-
Here's the reasoning behind each example:
|
|
68
|
-
${examples.map((x, idx) => `■${idx}:${!!x.filter ? 'true' : 'false'}:${x.reason ?? 'No reason provided'}`).join('\n')}
|
|
69
|
-
`.trim();
|
|
70
|
-
};
|
|
71
|
-
const genericExamples = [
|
|
72
|
-
{
|
|
73
|
-
input: 'apple',
|
|
74
|
-
filter: true,
|
|
75
|
-
reason: 'Apples are fruits'
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
input: 'Apple Inc.',
|
|
79
|
-
filter: false,
|
|
80
|
-
reason: 'Apple Inc. is a company, not a fruit'
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
input: 'banana',
|
|
84
|
-
filter: true,
|
|
85
|
-
reason: 'Bananas are fruits'
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
input: 'potato',
|
|
89
|
-
filter: false,
|
|
90
|
-
reason: 'Potatoes are vegetables'
|
|
91
|
-
}
|
|
92
|
-
];
|
|
93
|
-
const genericExamplesMessages = [
|
|
94
|
-
{
|
|
95
|
-
type: 'text',
|
|
96
|
-
content: formatInput(genericExamples, 'is a fruit'),
|
|
97
|
-
role: 'user'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
type: 'text',
|
|
101
|
-
content: formatExamples(genericExamples),
|
|
102
|
-
role: 'assistant'
|
|
103
|
-
}
|
|
104
|
-
];
|
|
105
|
-
const filterChunk = async (chunk) => {
|
|
106
|
-
const examples = taskId
|
|
107
|
-
? await this.adapter
|
|
108
|
-
.getExamples({
|
|
109
|
-
// The Table API can't search for a huge input string
|
|
110
|
-
input: JSON.stringify(chunk).slice(0, 1000),
|
|
111
|
-
taskType,
|
|
112
|
-
taskId
|
|
113
|
-
})
|
|
114
|
-
.then((x) => x.map((y) => ({ filter: y.output, input: y.input, reason: y.explanation })))
|
|
115
|
-
: [];
|
|
116
|
-
const allExamples = takeUntilTokens([...examples, ...(options.examples ?? [])], TOKENS_EXAMPLES_MAX, (el) => tokenizer.count(stringify(el.input)));
|
|
117
|
-
const exampleMessages = [
|
|
118
|
-
{
|
|
119
|
-
type: 'text',
|
|
120
|
-
content: formatInput(allExamples, condition),
|
|
121
|
-
role: 'user'
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
type: 'text',
|
|
125
|
-
content: formatExamples(allExamples),
|
|
126
|
-
role: 'assistant'
|
|
127
|
-
}
|
|
128
|
-
];
|
|
129
|
-
const output = await this.callModel({
|
|
130
|
-
systemPrompt: `
|
|
131
|
-
You are given a list of items. Your task is to filter out the items that meet the condition below.
|
|
132
|
-
You need to return the full list of items with the format:
|
|
133
|
-
■x:true■y:false■z:true (where x, y, z are the indices of the items in the list)
|
|
134
|
-
You need to start with "■0" and go up to the last index "■${chunk.length - 1}".
|
|
135
|
-
If an item meets the condition, you should return ":true", otherwise ":false".
|
|
136
|
-
|
|
137
|
-
IMPORTANT: Make sure to read the condition and the examples carefully before making your decision.
|
|
138
|
-
The condition is: "${condition}"
|
|
139
|
-
`.trim(),
|
|
140
|
-
stopSequences: [END],
|
|
141
|
-
messages: [
|
|
142
|
-
...(exampleMessages.length ? exampleMessages : genericExamplesMessages),
|
|
143
|
-
{
|
|
144
|
-
type: 'text',
|
|
145
|
-
content: formatInput(chunk.map((x) => ({ input: x })), condition),
|
|
146
|
-
role: 'user'
|
|
147
|
-
}
|
|
148
|
-
]
|
|
149
|
-
});
|
|
150
|
-
const answer = output.choices[0].content;
|
|
151
|
-
const indices = answer
|
|
152
|
-
.trim()
|
|
153
|
-
.split('■')
|
|
154
|
-
.filter((x) => x.length > 0)
|
|
155
|
-
.map((x) => {
|
|
156
|
-
const [idx, filter] = x.split(':');
|
|
157
|
-
return { idx: parseInt(idx.trim()), filter: filter.toLowerCase().trim() === 'true' };
|
|
158
|
-
});
|
|
159
|
-
const partial = chunk.filter((_, idx) => {
|
|
160
|
-
return indices.find((x) => x.idx === idx)?.filter ?? false;
|
|
161
|
-
});
|
|
162
|
-
if (taskId) {
|
|
163
|
-
const key = fastHash(stringify({
|
|
164
|
-
taskId,
|
|
165
|
-
taskType,
|
|
166
|
-
input: JSON.stringify(chunk),
|
|
167
|
-
condition
|
|
168
|
-
}));
|
|
169
|
-
await this.adapter.saveExample({
|
|
170
|
-
key,
|
|
171
|
-
taskType,
|
|
172
|
-
taskId,
|
|
173
|
-
input: JSON.stringify(chunk),
|
|
174
|
-
output: partial,
|
|
175
|
-
instructions: condition,
|
|
176
|
-
metadata: output.metadata
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
return partial;
|
|
180
|
-
};
|
|
181
|
-
const filteredChunks = await Promise.all(chunks.map(filterChunk));
|
|
182
|
-
return filteredChunks.flat();
|
|
183
|
-
};
|
|
184
|
-
//# sourceMappingURL=filter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../../../src/operations/filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,iBAAiB,CAAA;AAEnC,OAAO,CAAC,MAAM,QAAQ,CAAA;AACtB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/D,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,KAAK,EAAE,CAAC,CAAC,GAAG,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAA;AAGF,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC;IACvB,aAAa,EAAE,CAAC;SACb,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,OAAO,CAAC;SACZ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S,CAAC,KAAK,CAAC;gBAC5B,SAAS;aACV,CAAC,CACH,CAAA;YAED,MAAM,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;gBAC7B,GAAG;gBACH,QAAQ;gBACR,MAAM;gBACN,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBAC5B,MAAM,EAAE,OAAO;gBACf,YAAY,EAAE,SAAS;gBACvB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;IAED,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjE,OAAO,cAAc,CAAC,IAAI,EAAE,CAAA;AAC9B,CAAC,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from 'vitest';
|
|
2
|
-
import { getClient, getZai, metadata } from './__tests';
|
|
3
|
-
import { TableAdapter } from '../adapters/botpress-table';
|
|
4
|
-
describe('zai.filter', { timeout: 60_000 }, () => {
|
|
5
|
-
let zai = getZai();
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
zai = getZai();
|
|
8
|
-
});
|
|
9
|
-
it('basic filter with small items', async () => {
|
|
10
|
-
const value = await zai.filter([
|
|
11
|
-
{ name: 'John', description: 'is a bad person' },
|
|
12
|
-
{ name: 'Alice', description: 'is a good person' },
|
|
13
|
-
{ name: 'Bob', description: 'is a good person' },
|
|
14
|
-
{ name: 'Eve', description: 'is a bad person' },
|
|
15
|
-
{ name: 'Alex', description: 'is a good person' },
|
|
16
|
-
{ name: 'Sara', description: 'donates to charity every month' },
|
|
17
|
-
{ name: 'Tom', description: 'commits crimes and is in jail' }
|
|
18
|
-
], 'generally good people');
|
|
19
|
-
const names = value.map((v) => v.name);
|
|
20
|
-
expect(names).toMatchInlineSnapshot(`
|
|
21
|
-
[
|
|
22
|
-
"Alice",
|
|
23
|
-
"Bob",
|
|
24
|
-
"Alex",
|
|
25
|
-
"Sara",
|
|
26
|
-
]
|
|
27
|
-
`);
|
|
28
|
-
});
|
|
29
|
-
it('filtering huge array chunks it up', async () => {
|
|
30
|
-
const callAction = vi.fn();
|
|
31
|
-
const client = { ...getClient(), callAction };
|
|
32
|
-
zai = getZai().with({
|
|
33
|
-
client
|
|
34
|
-
});
|
|
35
|
-
const hugeArray = Array.from({ length: 100 }, (_, i) => ({
|
|
36
|
-
name: `Person #${i}#`,
|
|
37
|
-
description: 'blah blah '.repeat(50_000)
|
|
38
|
-
}));
|
|
39
|
-
try {
|
|
40
|
-
await zai.filter(hugeArray, 'generally good people', { tokensPerItem: 100_000 });
|
|
41
|
-
}
|
|
42
|
-
catch (err) { }
|
|
43
|
-
expect(callAction.mock.calls.length).toBeGreaterThan(20);
|
|
44
|
-
expect(JSON.stringify(callAction.mock.calls.at(0))).toContain('Person #0#');
|
|
45
|
-
expect(JSON.stringify(callAction.mock.calls.at(0))).not.toContain('Person #99#');
|
|
46
|
-
expect(JSON.stringify(callAction.mock.calls.at(-1))).not.toContain('Person #0#');
|
|
47
|
-
expect(JSON.stringify(callAction.mock.calls.at(-1))).toContain('Person #99#');
|
|
48
|
-
callAction.mockReset();
|
|
49
|
-
try {
|
|
50
|
-
await zai.filter(hugeArray, 'generally good people', { tokensPerItem: 100 });
|
|
51
|
-
}
|
|
52
|
-
catch (err) { }
|
|
53
|
-
expect(callAction.mock.calls.length).toBe(2);
|
|
54
|
-
});
|
|
55
|
-
it('filter with examples', async () => {
|
|
56
|
-
const examples = [
|
|
57
|
-
{
|
|
58
|
-
input: 'Rasa (framework)',
|
|
59
|
-
filter: true,
|
|
60
|
-
reason: 'Rasa is a chatbot framework, so it competes with us (Botpress).'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
input: 'Rasa (coffee company)',
|
|
64
|
-
filter: false,
|
|
65
|
-
reason: 'Rasa (coffee company) is not in the chatbot or AI agent industry, therefore it does not compete with us (Botpress).'
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
input: 'Dialogflow',
|
|
69
|
-
filter: true,
|
|
70
|
-
reason: 'Dialogflow is a chatbot development product, so it competes with us (Botpress).'
|
|
71
|
-
}
|
|
72
|
-
];
|
|
73
|
-
const value = await zai.filter([{ name: 'Moveworks' }, { name: 'Ada.cx' }, { name: 'Nike' }, { name: 'Voiceflow' }, { name: 'Adidas' }], 'competes with us', { examples });
|
|
74
|
-
const names = value.map((v) => v.name);
|
|
75
|
-
expect(names).toMatchInlineSnapshot(`
|
|
76
|
-
[
|
|
77
|
-
"Moveworks",
|
|
78
|
-
"Ada.cx",
|
|
79
|
-
"Voiceflow",
|
|
80
|
-
]
|
|
81
|
-
`);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
describe('zai.learn.filter', { timeout: 60_000 }, () => {
|
|
85
|
-
const client = getClient();
|
|
86
|
-
let tableName = 'ZaiTestFilterInternalTable';
|
|
87
|
-
let taskId = 'filter';
|
|
88
|
-
let zai = getZai();
|
|
89
|
-
beforeEach(async () => {
|
|
90
|
-
zai = getZai().with({
|
|
91
|
-
activeLearning: {
|
|
92
|
-
enable: true,
|
|
93
|
-
taskId,
|
|
94
|
-
tableName
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
afterEach(async () => {
|
|
99
|
-
try {
|
|
100
|
-
await client.deleteTableRows({ table: tableName, deleteAllRows: true });
|
|
101
|
-
}
|
|
102
|
-
catch (err) { }
|
|
103
|
-
});
|
|
104
|
-
afterAll(async () => {
|
|
105
|
-
try {
|
|
106
|
-
await client.deleteTable({ table: tableName });
|
|
107
|
-
}
|
|
108
|
-
catch (err) { }
|
|
109
|
-
});
|
|
110
|
-
it('learns a filtering rule from examples', async () => {
|
|
111
|
-
const adapter = new TableAdapter({
|
|
112
|
-
client,
|
|
113
|
-
tableName
|
|
114
|
-
});
|
|
115
|
-
await adapter.saveExample({
|
|
116
|
-
key: 't1',
|
|
117
|
-
taskId: `zai/${taskId}`,
|
|
118
|
-
taskType: 'zai.filter',
|
|
119
|
-
instructions: 'competes with us?',
|
|
120
|
-
input: ['Rasa (framework)', 'Rasa (coffee company)'],
|
|
121
|
-
output: ['Rasa (framework)'],
|
|
122
|
-
explanation: `Rasa is a chatbot framework, so it competes with us (Botpress). We should keep it. Rasa (coffee company) is not in the chatbot or AI agent industry, therefore it does not compete with us (Botpress). We should filter it out.`,
|
|
123
|
-
metadata,
|
|
124
|
-
status: 'approved'
|
|
125
|
-
});
|
|
126
|
-
await adapter.saveExample({
|
|
127
|
-
key: 't2',
|
|
128
|
-
taskId: `zai/${taskId}`,
|
|
129
|
-
taskType: 'zai.filter',
|
|
130
|
-
instructions: 'competes with us?',
|
|
131
|
-
input: ['Voiceflow', 'Dialogflow'],
|
|
132
|
-
output: ['Voiceflow', 'Dialogflow'],
|
|
133
|
-
explanation: `Voiceflow is a chatbot development product, so it competes with us (Botpress). We should keep it. Dialogflow is a chatbot development product, so it competes with us (Botpress). We should keep it.`,
|
|
134
|
-
metadata,
|
|
135
|
-
status: 'approved'
|
|
136
|
-
});
|
|
137
|
-
const second = await zai
|
|
138
|
-
.learn(taskId)
|
|
139
|
-
.filter(['Nike', 'Ada.cx', 'Adidas', 'Moveworks', 'Lululemon'], 'competes with us? (botpress)');
|
|
140
|
-
expect(second).toMatchInlineSnapshot(`
|
|
141
|
-
[
|
|
142
|
-
"Ada.cx",
|
|
143
|
-
"Moveworks",
|
|
144
|
-
]
|
|
145
|
-
`);
|
|
146
|
-
const rows = await client.findTableRows({ table: tableName });
|
|
147
|
-
expect(rows.rows.length).toBe(3);
|
|
148
|
-
expect(rows.rows.at(-1).output.value).toEqual(second);
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
//# sourceMappingURL=filter.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|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AAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACxD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { z } from '@bpinternal/zui';
|
|
2
|
-
type Label = keyof typeof LABELS;
|
|
3
|
-
declare const LABELS: {
|
|
4
|
-
readonly ABSOLUTELY_NOT: "ABSOLUTELY_NOT";
|
|
5
|
-
readonly PROBABLY_NOT: "PROBABLY_NOT";
|
|
6
|
-
readonly AMBIGUOUS: "AMBIGUOUS";
|
|
7
|
-
readonly PROBABLY_YES: "PROBABLY_YES";
|
|
8
|
-
readonly ABSOLUTELY_YES: "ABSOLUTELY_YES";
|
|
9
|
-
};
|
|
10
|
-
type Example<T extends string> = {
|
|
11
|
-
input: unknown;
|
|
12
|
-
labels: Partial<Record<T, {
|
|
13
|
-
label: Label;
|
|
14
|
-
explanation?: string;
|
|
15
|
-
}>>;
|
|
16
|
-
};
|
|
17
|
-
export type Options<T extends string> = Omit<z.input<typeof Options>, 'examples'> & {
|
|
18
|
-
examples?: Array<Partial<Example<T>>>;
|
|
19
|
-
};
|
|
20
|
-
declare const Options: import("@bpinternal/zui").ZodObject<{
|
|
21
|
-
examples: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodArray<import("@bpinternal/zui").ZodObject<{
|
|
22
|
-
input: import("@bpinternal/zui").ZodAny;
|
|
23
|
-
labels: import("@bpinternal/zui").ZodRecord<import("@bpinternal/zui").ZodString, import("@bpinternal/zui").ZodObject<{
|
|
24
|
-
label: import("@bpinternal/zui").ZodEnum<never>;
|
|
25
|
-
explanation: import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodString>;
|
|
26
|
-
}, "strip", import("@bpinternal/zui").ZodTypeAny, {
|
|
27
|
-
label: never;
|
|
28
|
-
explanation?: string | undefined;
|
|
29
|
-
}, {
|
|
30
|
-
label: never;
|
|
31
|
-
explanation?: string | undefined;
|
|
32
|
-
}>>;
|
|
33
|
-
}, "strip", import("@bpinternal/zui").ZodTypeAny, {
|
|
34
|
-
labels: Record<string, {
|
|
35
|
-
label: never;
|
|
36
|
-
explanation?: string | undefined;
|
|
37
|
-
}>;
|
|
38
|
-
input?: any;
|
|
39
|
-
}, {
|
|
40
|
-
labels: Record<string, {
|
|
41
|
-
label: never;
|
|
42
|
-
explanation?: string | undefined;
|
|
43
|
-
}>;
|
|
44
|
-
input?: any;
|
|
45
|
-
}>, "many">>;
|
|
46
|
-
instructions: import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodString>;
|
|
47
|
-
chunkLength: import("@bpinternal/zui").ZodDefault<import("@bpinternal/zui").ZodOptional<import("@bpinternal/zui").ZodNumber>>;
|
|
48
|
-
}, "strip", import("@bpinternal/zui").ZodTypeAny, {
|
|
49
|
-
examples: {
|
|
50
|
-
labels: Record<string, {
|
|
51
|
-
label: never;
|
|
52
|
-
explanation?: string | undefined;
|
|
53
|
-
}>;
|
|
54
|
-
input?: any;
|
|
55
|
-
}[];
|
|
56
|
-
chunkLength: number;
|
|
57
|
-
instructions?: string | undefined;
|
|
58
|
-
}, {
|
|
59
|
-
instructions?: string | undefined;
|
|
60
|
-
examples?: {
|
|
61
|
-
labels: Record<string, {
|
|
62
|
-
label: never;
|
|
63
|
-
explanation?: string | undefined;
|
|
64
|
-
}>;
|
|
65
|
-
input?: any;
|
|
66
|
-
}[] | undefined;
|
|
67
|
-
chunkLength?: number | undefined;
|
|
68
|
-
}>;
|
|
69
|
-
type Labels<T extends string> = Record<T, string>;
|
|
70
|
-
declare const Labels: z.ZodTransformer<import("@bpinternal/zui").ZodRecord<import("@bpinternal/zui").ZodString, import("@bpinternal/zui").ZodString>, Record<string, string>, Record<string, string>>;
|
|
71
|
-
declare module '../zai' {
|
|
72
|
-
interface Zai {
|
|
73
|
-
/** Tags the provided input with a list of predefined labels */
|
|
74
|
-
label<T extends string>(input: unknown, labels: Labels<T>, options?: Options<T>): Promise<{
|
|
75
|
-
[K in T]: boolean;
|
|
76
|
-
}>;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export {};
|