@botpress/zai 1.0.1-beta.1 → 1.0.1-beta.3

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 (47) hide show
  1. package/dist/browser/index.js +4071 -0
  2. package/dist/{csj → node}/adapters/botpress-table.js +1 -2
  3. package/dist/{csj → node}/operations/check.js +1 -2
  4. package/dist/{csj → node}/operations/extract.js +8 -9
  5. package/dist/{csj → node}/operations/filter.js +4 -5
  6. package/dist/{csj → node}/operations/label.js +7 -8
  7. package/dist/{csj → node}/operations/rewrite.js +1 -2
  8. package/dist/{csj → node}/operations/summarize.js +4 -5
  9. package/dist/{csj → node}/operations/text.js +3 -4
  10. package/dist/{csj → node}/utils.js +1 -2
  11. package/dist/{csj → node}/zai.js +1 -2
  12. package/package.json +17 -12
  13. package/scripts/update-models.mts +3 -3
  14. package/scripts/update-types.mts +5 -15
  15. package/src/adapters/botpress-table.ts +3 -4
  16. package/src/operations/__tests/index.ts +1 -0
  17. package/src/operations/check.ts +2 -3
  18. package/src/operations/extract.ts +13 -14
  19. package/src/operations/filter.ts +5 -6
  20. package/src/operations/label.ts +7 -8
  21. package/src/operations/rewrite.ts +3 -4
  22. package/src/operations/summarize.ts +4 -5
  23. package/src/operations/text.ts +4 -5
  24. package/src/utils.ts +1 -2
  25. package/src/zai.ts +4 -4
  26. package/dist/esm/adapters/adapter.js +0 -5
  27. package/dist/esm/adapters/botpress-table.js +0 -194
  28. package/dist/esm/adapters/memory.js +0 -15
  29. package/dist/esm/index.js +0 -11
  30. package/dist/esm/models.js +0 -390
  31. package/dist/esm/operations/check.js +0 -149
  32. package/dist/esm/operations/constants.js +0 -6
  33. package/dist/esm/operations/errors.js +0 -18
  34. package/dist/esm/operations/extract.js +0 -217
  35. package/dist/esm/operations/filter.js +0 -189
  36. package/dist/esm/operations/label.js +0 -246
  37. package/dist/esm/operations/rewrite.js +0 -113
  38. package/dist/esm/operations/summarize.js +0 -134
  39. package/dist/esm/operations/text.js +0 -48
  40. package/dist/esm/utils.js +0 -51
  41. package/dist/esm/zai.js +0 -161
  42. /package/dist/{csj → node}/adapters/adapter.js +0 -0
  43. /package/dist/{csj → node}/adapters/memory.js +0 -0
  44. /package/dist/{csj → node}/index.js +0 -0
  45. /package/dist/{csj → node}/models.js +0 -0
  46. /package/dist/{csj → node}/operations/constants.js +0 -0
  47. /package/dist/{csj → node}/operations/errors.js +0 -0
@@ -1,194 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
- import sdk from "@botpress/sdk";
19
- const { z } = sdk;
20
- import { BotpressClient, GenerationMetadata } from "../utils";
21
- import { Adapter } from "./adapter";
22
- const CRITICAL_TAGS = {
23
- system: "true",
24
- "schema-purpose": "active-learning",
25
- "schema-version": "Oct-2024"
26
- };
27
- const OPTIONAL_TAGS = {
28
- "x-studio-title": "Active Learning",
29
- "x-studio-description": "Table for storing active learning tasks and examples",
30
- "x-studio-readonly": "true",
31
- "x-studio-icon": "lucide://atom",
32
- "x-studio-color": "green"
33
- };
34
- const FACTOR = 30;
35
- const Props = z.object({
36
- client: BotpressClient,
37
- tableName: z.string().regex(
38
- /^[a-zA-Z0-9_]{1,45}Table$/,
39
- "Table name must be lowercase and contain only letters, numbers and underscores"
40
- )
41
- });
42
- const TableSchema = z.object({
43
- taskType: z.string().describe("The type of the task (filter, extract, etc.)"),
44
- taskId: z.string(),
45
- key: z.string().describe("A unique key for the task (e.g. a hash of the input, taskId, taskType and instructions)"),
46
- instructions: z.string(),
47
- input: z.object({}).passthrough().describe("The input to the task"),
48
- output: z.object({}).passthrough().describe("The expected output"),
49
- explanation: z.string().nullable(),
50
- metadata: GenerationMetadata,
51
- status: z.enum(["pending", "rejected", "approved"]),
52
- feedback: z.object({
53
- rating: z.enum(["very-bad", "bad", "good", "very-good"]),
54
- comment: z.string().nullable()
55
- }).nullable().default(null)
56
- });
57
- const searchableColumns = ["input"];
58
- const TableJsonSchema = Object.entries(TableSchema.shape).reduce((acc, [key, value]) => {
59
- var _a, _b;
60
- acc[key] = value.toJsonSchema();
61
- (_b = (_a = acc[key])["x-zui"]) != null ? _b : _a["x-zui"] = {};
62
- acc[key]["x-zui"].searchable = searchableColumns.includes(key);
63
- return acc;
64
- }, {});
65
- class TableAdapter extends Adapter {
66
- constructor(props) {
67
- super();
68
- __publicField(this, "client");
69
- __publicField(this, "tableName");
70
- __publicField(this, "status");
71
- __publicField(this, "errors", []);
72
- props = Props.parse(props);
73
- this.client = props.client;
74
- this.tableName = props.tableName;
75
- this.status = "ready";
76
- }
77
- async getExamples({ taskType, taskId, input }) {
78
- await this.assertTableExists();
79
- const { rows } = await this.client.findTableRows({
80
- table: this.tableName,
81
- search: JSON.stringify({ value: input }).substring(0, 1023),
82
- // Search is limited to 1024 characters
83
- limit: 10,
84
- // TODO
85
- filter: {
86
- // Proximity match of approved examples
87
- taskType,
88
- taskId,
89
- status: "approved"
90
- }
91
- }).catch((err) => {
92
- console.error(`Error fetching examples: ${err.message}`);
93
- return { rows: [] };
94
- });
95
- return rows.map((row) => {
96
- var _a;
97
- return {
98
- key: row.key,
99
- input: row.input.value,
100
- output: row.output.value,
101
- explanation: row.explanation,
102
- similarity: (_a = row.similarity) != null ? _a : 0
103
- };
104
- });
105
- }
106
- async saveExample({
107
- key,
108
- taskType,
109
- taskId,
110
- instructions,
111
- input,
112
- output,
113
- explanation,
114
- metadata,
115
- status = "pending"
116
- }) {
117
- await this.assertTableExists();
118
- await this.client.upsertTableRows({
119
- table: this.tableName,
120
- keyColumn: "key",
121
- rows: [
122
- {
123
- key,
124
- taskType,
125
- taskId,
126
- instructions,
127
- input: { value: input },
128
- output: { value: output },
129
- explanation: explanation != null ? explanation : null,
130
- status,
131
- metadata
132
- }
133
- ]
134
- }).catch(() => {
135
- });
136
- }
137
- async assertTableExists() {
138
- var _a, _b, _c;
139
- if (this.status !== "ready") {
140
- return;
141
- }
142
- const { table, created } = await this.client.getOrCreateTable({
143
- table: this.tableName,
144
- factor: FACTOR,
145
- frozen: true,
146
- isComputeEnabled: false,
147
- tags: __spreadValues(__spreadValues({}, CRITICAL_TAGS), OPTIONAL_TAGS),
148
- schema: TableJsonSchema
149
- }).catch((err) => {
150
- this.status = "error";
151
- this.errors = [err.message];
152
- return { table: null, created: false };
153
- });
154
- if (!table) {
155
- return;
156
- }
157
- if (!created) {
158
- const issues = [];
159
- if (table.factor !== FACTOR) {
160
- issues.push(`Factor is ${table.factor} instead of ${FACTOR}`);
161
- }
162
- if (table.frozen !== true) {
163
- issues.push("Table is not frozen");
164
- }
165
- for (const [key, value] of Object.entries(CRITICAL_TAGS)) {
166
- if (((_a = table.tags) == null ? void 0 : _a[key]) !== value) {
167
- issues.push(`Tag ${key} is ${(_b = table.tags) == null ? void 0 : _b[key]} instead of ${value}`);
168
- }
169
- }
170
- for (const key of Object.keys(TableJsonSchema)) {
171
- const column = (_c = table.schema) == null ? void 0 : _c.properties[key];
172
- const expected = TableJsonSchema[key];
173
- if (!column) {
174
- issues.push(`Column ${key} is missing`);
175
- continue;
176
- }
177
- if (column.type !== expected.type) {
178
- issues.push(`Column ${key} has type ${column.type} instead of ${expected.type}`);
179
- }
180
- if (expected["x-zui"].searchable && !column["x-zui"].searchable) {
181
- issues.push(`Column ${key} is not searchable but should be`);
182
- }
183
- }
184
- if (issues.length) {
185
- this.status = "error";
186
- this.errors = issues;
187
- }
188
- }
189
- this.status = "initialized";
190
- }
191
- }
192
- export {
193
- TableAdapter
194
- };
@@ -1,15 +0,0 @@
1
- import { Adapter } from "./adapter";
2
- class MemoryAdapter extends Adapter {
3
- constructor(examples) {
4
- super();
5
- this.examples = examples;
6
- }
7
- async getExamples() {
8
- return this.examples;
9
- }
10
- async saveExample() {
11
- }
12
- }
13
- export {
14
- MemoryAdapter
15
- };
package/dist/esm/index.js DELETED
@@ -1,11 +0,0 @@
1
- import { Zai } from "./zai";
2
- import "./operations/text";
3
- import "./operations/rewrite";
4
- import "./operations/summarize";
5
- import "./operations/check";
6
- import "./operations/filter";
7
- import "./operations/extract";
8
- import "./operations/label";
9
- export {
10
- Zai
11
- };
@@ -1,390 +0,0 @@
1
- const Models = [
2
- {
3
- "id": "anthropic__claude-3-haiku-20240307",
4
- "name": "Claude 3 Haiku",
5
- "integration": "anthropic",
6
- "input": {
7
- "maxTokens": 2e5
8
- },
9
- "output": {
10
- "maxTokens": 4096
11
- }
12
- },
13
- {
14
- "id": "anthropic__claude-3-5-sonnet-20240620",
15
- "name": "Claude 3.5 Sonnet",
16
- "integration": "anthropic",
17
- "input": {
18
- "maxTokens": 2e5
19
- },
20
- "output": {
21
- "maxTokens": 4096
22
- }
23
- },
24
- {
25
- "id": "cerebras__llama3.1-70b",
26
- "name": "Llama 3.1 70B",
27
- "integration": "cerebras",
28
- "input": {
29
- "maxTokens": 8192
30
- },
31
- "output": {
32
- "maxTokens": 8192
33
- }
34
- },
35
- {
36
- "id": "cerebras__llama3.1-8b",
37
- "name": "Llama 3.1 8B",
38
- "integration": "cerebras",
39
- "input": {
40
- "maxTokens": 8192
41
- },
42
- "output": {
43
- "maxTokens": 8192
44
- }
45
- },
46
- {
47
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct",
48
- "name": "DeepSeek Coder V2 Instruct",
49
- "integration": "fireworks-ai",
50
- "input": {
51
- "maxTokens": 131072
52
- },
53
- "output": {
54
- "maxTokens": 131072
55
- }
56
- },
57
- {
58
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct",
59
- "name": "DeepSeek Coder V2 Lite",
60
- "integration": "fireworks-ai",
61
- "input": {
62
- "maxTokens": 163840
63
- },
64
- "output": {
65
- "maxTokens": 163840
66
- }
67
- },
68
- {
69
- "id": "fireworks-ai__accounts/fireworks/models/firellava-13b",
70
- "name": "FireLLaVA-13B",
71
- "integration": "fireworks-ai",
72
- "input": {
73
- "maxTokens": 4096
74
- },
75
- "output": {
76
- "maxTokens": 4096
77
- }
78
- },
79
- {
80
- "id": "fireworks-ai__accounts/fireworks/models/firefunction-v2",
81
- "name": "Firefunction V2",
82
- "integration": "fireworks-ai",
83
- "input": {
84
- "maxTokens": 8192
85
- },
86
- "output": {
87
- "maxTokens": 8192
88
- }
89
- },
90
- {
91
- "id": "fireworks-ai__accounts/fireworks/models/gemma2-9b-it",
92
- "name": "Gemma 2 9B Instruct",
93
- "integration": "fireworks-ai",
94
- "input": {
95
- "maxTokens": 8192
96
- },
97
- "output": {
98
- "maxTokens": 8192
99
- }
100
- },
101
- {
102
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct",
103
- "name": "Llama 3.1 405B Instruct",
104
- "integration": "fireworks-ai",
105
- "input": {
106
- "maxTokens": 131072
107
- },
108
- "output": {
109
- "maxTokens": 131072
110
- }
111
- },
112
- {
113
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct",
114
- "name": "Llama 3.1 70B Instruct",
115
- "integration": "fireworks-ai",
116
- "input": {
117
- "maxTokens": 131072
118
- },
119
- "output": {
120
- "maxTokens": 131072
121
- }
122
- },
123
- {
124
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct",
125
- "name": "Llama 3.1 8B Instruct",
126
- "integration": "fireworks-ai",
127
- "input": {
128
- "maxTokens": 131072
129
- },
130
- "output": {
131
- "maxTokens": 131072
132
- }
133
- },
134
- {
135
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct",
136
- "name": "Mixtral MoE 8x22B Instruct",
137
- "integration": "fireworks-ai",
138
- "input": {
139
- "maxTokens": 65536
140
- },
141
- "output": {
142
- "maxTokens": 65536
143
- }
144
- },
145
- {
146
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct",
147
- "name": "Mixtral MoE 8x7B Instruct",
148
- "integration": "fireworks-ai",
149
- "input": {
150
- "maxTokens": 32768
151
- },
152
- "output": {
153
- "maxTokens": 32768
154
- }
155
- },
156
- {
157
- "id": "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b",
158
- "name": "MythoMax L2 13b",
159
- "integration": "fireworks-ai",
160
- "input": {
161
- "maxTokens": 4096
162
- },
163
- "output": {
164
- "maxTokens": 4096
165
- }
166
- },
167
- {
168
- "id": "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct",
169
- "name": "Qwen2 72b Instruct",
170
- "integration": "fireworks-ai",
171
- "input": {
172
- "maxTokens": 32768
173
- },
174
- "output": {
175
- "maxTokens": 32768
176
- }
177
- },
178
- {
179
- "id": "groq__gemma2-9b-it",
180
- "name": "Gemma2 9B",
181
- "integration": "groq",
182
- "input": {
183
- "maxTokens": 8192
184
- },
185
- "output": {
186
- "maxTokens": 8192
187
- }
188
- },
189
- {
190
- "id": "groq__llama3-70b-8192",
191
- "name": "LLaMA 3 70B",
192
- "integration": "groq",
193
- "input": {
194
- "maxTokens": 8192
195
- },
196
- "output": {
197
- "maxTokens": 8192
198
- }
199
- },
200
- {
201
- "id": "groq__llama3-8b-8192",
202
- "name": "LLaMA 3 8B",
203
- "integration": "groq",
204
- "input": {
205
- "maxTokens": 8192
206
- },
207
- "output": {
208
- "maxTokens": 8192
209
- }
210
- },
211
- {
212
- "id": "groq__llama-3.1-70b-versatile",
213
- "name": "LLaMA 3.1 70B",
214
- "integration": "groq",
215
- "input": {
216
- "maxTokens": 128e3
217
- },
218
- "output": {
219
- "maxTokens": 8192
220
- }
221
- },
222
- {
223
- "id": "groq__llama-3.1-8b-instant",
224
- "name": "LLaMA 3.1 8B",
225
- "integration": "groq",
226
- "input": {
227
- "maxTokens": 128e3
228
- },
229
- "output": {
230
- "maxTokens": 8192
231
- }
232
- },
233
- {
234
- "id": "groq__llama-3.2-11b-vision-preview",
235
- "name": "LLaMA 3.2 11B Vision",
236
- "integration": "groq",
237
- "input": {
238
- "maxTokens": 128e3
239
- },
240
- "output": {
241
- "maxTokens": 8192
242
- }
243
- },
244
- {
245
- "id": "groq__llama-3.2-1b-preview",
246
- "name": "LLaMA 3.2 1B",
247
- "integration": "groq",
248
- "input": {
249
- "maxTokens": 128e3
250
- },
251
- "output": {
252
- "maxTokens": 8192
253
- }
254
- },
255
- {
256
- "id": "groq__llama-3.2-3b-preview",
257
- "name": "LLaMA 3.2 3B",
258
- "integration": "groq",
259
- "input": {
260
- "maxTokens": 128e3
261
- },
262
- "output": {
263
- "maxTokens": 8192
264
- }
265
- },
266
- {
267
- "id": "groq__llama-3.2-90b-vision-preview",
268
- "name": "LLaMA 3.2 90B Vision",
269
- "integration": "groq",
270
- "input": {
271
- "maxTokens": 128e3
272
- },
273
- "output": {
274
- "maxTokens": 8192
275
- }
276
- },
277
- {
278
- "id": "groq__llama-3.3-70b-versatile",
279
- "name": "LLaMA 3.3 70B",
280
- "integration": "groq",
281
- "input": {
282
- "maxTokens": 128e3
283
- },
284
- "output": {
285
- "maxTokens": 32768
286
- }
287
- },
288
- {
289
- "id": "groq__mixtral-8x7b-32768",
290
- "name": "Mixtral 8x7B",
291
- "integration": "groq",
292
- "input": {
293
- "maxTokens": 32768
294
- },
295
- "output": {
296
- "maxTokens": 32768
297
- }
298
- },
299
- {
300
- "id": "openai__o1-2024-12-17",
301
- "name": "GPT o1",
302
- "integration": "openai",
303
- "input": {
304
- "maxTokens": 2e5
305
- },
306
- "output": {
307
- "maxTokens": 1e5
308
- }
309
- },
310
- {
311
- "id": "openai__o1-mini-2024-09-12",
312
- "name": "GPT o1-mini",
313
- "integration": "openai",
314
- "input": {
315
- "maxTokens": 128e3
316
- },
317
- "output": {
318
- "maxTokens": 65536
319
- }
320
- },
321
- {
322
- "id": "openai__gpt-3.5-turbo-0125",
323
- "name": "GPT-3.5 Turbo",
324
- "integration": "openai",
325
- "input": {
326
- "maxTokens": 128e3
327
- },
328
- "output": {
329
- "maxTokens": 4096
330
- }
331
- },
332
- {
333
- "id": "openai__gpt-4-turbo-2024-04-09",
334
- "name": "GPT-4 Turbo",
335
- "integration": "openai",
336
- "input": {
337
- "maxTokens": 128e3
338
- },
339
- "output": {
340
- "maxTokens": 4096
341
- }
342
- },
343
- {
344
- "id": "openai__gpt-4o-2024-08-06",
345
- "name": "GPT-4o (August 2024)",
346
- "integration": "openai",
347
- "input": {
348
- "maxTokens": 128e3
349
- },
350
- "output": {
351
- "maxTokens": 16384
352
- }
353
- },
354
- {
355
- "id": "openai__gpt-4o-2024-05-13",
356
- "name": "GPT-4o (May 2024)",
357
- "integration": "openai",
358
- "input": {
359
- "maxTokens": 128e3
360
- },
361
- "output": {
362
- "maxTokens": 4096
363
- }
364
- },
365
- {
366
- "id": "openai__gpt-4o-2024-11-20",
367
- "name": "GPT-4o (November 2024)",
368
- "integration": "openai",
369
- "input": {
370
- "maxTokens": 128e3
371
- },
372
- "output": {
373
- "maxTokens": 16384
374
- }
375
- },
376
- {
377
- "id": "openai__gpt-4o-mini-2024-07-18",
378
- "name": "GPT-4o Mini",
379
- "integration": "openai",
380
- "input": {
381
- "maxTokens": 128e3
382
- },
383
- "output": {
384
- "maxTokens": 16384
385
- }
386
- }
387
- ];
388
- export {
389
- Models
390
- };