@botpress/zai 1.0.1-beta.4 → 1.0.1-beta.5

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 (65) hide show
  1. package/dist/browser/index.js +1 -4
  2. package/dist/index.d.ts +917 -0
  3. package/dist/index.js +1743 -0
  4. package/dist/node/adapters/adapter.d.js +0 -0
  5. package/dist/node/adapters/botpress-table.d.js +1 -0
  6. package/dist/node/adapters/botpress-table.js +1 -4
  7. package/dist/node/adapters/memory.d.js +0 -0
  8. package/dist/node/index.d.js +9 -0
  9. package/dist/node/models.d.js +0 -0
  10. package/dist/node/operations/check.d.js +1 -0
  11. package/dist/node/operations/check.test.d.js +1 -0
  12. package/dist/node/operations/constants.d.js +0 -0
  13. package/dist/node/operations/errors.d.js +0 -0
  14. package/dist/node/operations/extract.d.js +1 -0
  15. package/dist/node/operations/extract.test.d.js +1 -0
  16. package/dist/node/operations/filter.d.js +1 -0
  17. package/dist/node/operations/filter.test.d.js +1 -0
  18. package/dist/node/operations/label.d.js +1 -0
  19. package/dist/node/operations/label.test.d.js +1 -0
  20. package/dist/node/operations/rewrite.d.js +1 -0
  21. package/dist/node/operations/rewrite.test.d.js +1 -0
  22. package/dist/node/operations/summarize.d.js +1 -0
  23. package/dist/node/operations/summarize.test.d.js +1 -0
  24. package/dist/node/operations/text.d.js +1 -0
  25. package/dist/node/operations/text.test.d.js +1 -0
  26. package/dist/node/operations/zai-learn.test.d.js +1 -0
  27. package/dist/node/operations/zai-retry.test.d.js +1 -0
  28. package/dist/node/utils.d.js +0 -0
  29. package/dist/node/zai.d.js +1 -0
  30. package/package.json +5 -14
  31. package/src/adapters/adapter.d.ts +27 -0
  32. package/src/adapters/botpress-table.d.ts +153 -0
  33. package/src/adapters/botpress-table.ts +1 -4
  34. package/src/adapters/memory.d.ts +7 -0
  35. package/src/index.d.ts +9 -0
  36. package/src/models.d.ts +351 -0
  37. package/src/operations/__tests/index.d.ts +20 -0
  38. package/src/operations/check.d.ts +36 -0
  39. package/src/operations/check.test.d.ts +1 -0
  40. package/src/operations/constants.d.ts +2 -0
  41. package/src/operations/errors.d.ts +5 -0
  42. package/src/operations/extract.d.ts +20 -0
  43. package/src/operations/extract.test.d.ts +1 -0
  44. package/src/operations/filter.d.ts +39 -0
  45. package/src/operations/filter.test.d.ts +1 -0
  46. package/src/operations/label.d.ts +79 -0
  47. package/src/operations/label.test.d.ts +1 -0
  48. package/src/operations/rewrite.d.ts +34 -0
  49. package/src/operations/rewrite.test.d.ts +1 -0
  50. package/src/operations/summarize.d.ts +46 -0
  51. package/src/operations/summarize.test.d.ts +1 -0
  52. package/src/operations/text.d.ts +16 -0
  53. package/src/operations/text.test.d.ts +1 -0
  54. package/src/operations/zai-learn.test.d.ts +1 -0
  55. package/src/operations/zai-retry.test.d.ts +1 -0
  56. package/src/sdk-interfaces/llm/generateContent.d.ts +128 -0
  57. package/src/sdk-interfaces/llm/listLanguageModels.d.ts +25 -0
  58. package/src/utils.d.ts +52 -0
  59. package/src/zai.d.ts +99 -0
  60. package/tsconfig.json +2 -2
  61. package/scripts/update-models.mts +0 -76
  62. package/scripts/update-types.mts +0 -49
  63. package/tsup.config.ts +0 -16
  64. package/vitest.config.ts +0 -9
  65. package/vitest.setup.ts +0 -24
@@ -0,0 +1,917 @@
1
+ import * as _bpinternal_zui from '@bpinternal/zui';
2
+ import { z } from '@bpinternal/zui';
3
+ import { Client } from '@botpress/client';
4
+ import { TextTokenizer } from '@botpress/wasm';
5
+
6
+ type GenerationMetadata = z.input<typeof GenerationMetadata>;
7
+ declare const GenerationMetadata: _bpinternal_zui.ZodObject<{
8
+ model: _bpinternal_zui.ZodString;
9
+ cost: _bpinternal_zui.ZodObject<{
10
+ input: _bpinternal_zui.ZodNumber;
11
+ output: _bpinternal_zui.ZodNumber;
12
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
13
+ input?: number;
14
+ output?: number;
15
+ }, {
16
+ input?: number;
17
+ output?: number;
18
+ }>;
19
+ latency: _bpinternal_zui.ZodNumber;
20
+ tokens: _bpinternal_zui.ZodObject<{
21
+ input: _bpinternal_zui.ZodNumber;
22
+ output: _bpinternal_zui.ZodNumber;
23
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
24
+ input?: number;
25
+ output?: number;
26
+ }, {
27
+ input?: number;
28
+ output?: number;
29
+ }>;
30
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
31
+ model?: string;
32
+ cost?: {
33
+ input?: number;
34
+ output?: number;
35
+ };
36
+ latency?: number;
37
+ tokens?: {
38
+ input?: number;
39
+ output?: number;
40
+ };
41
+ }, {
42
+ model?: string;
43
+ cost?: {
44
+ input?: number;
45
+ output?: number;
46
+ };
47
+ latency?: number;
48
+ tokens?: {
49
+ input?: number;
50
+ output?: number;
51
+ };
52
+ }>;
53
+
54
+ type SaveExampleProps<TInput, TOutput> = {
55
+ key: string;
56
+ taskType: string;
57
+ taskId: string;
58
+ instructions: string;
59
+ input: TInput;
60
+ output: TOutput;
61
+ explanation?: string;
62
+ metadata: GenerationMetadata;
63
+ status?: 'pending' | 'approved';
64
+ };
65
+ type GetExamplesProps<TInput> = {
66
+ taskType: string;
67
+ taskId: string;
68
+ input: TInput;
69
+ };
70
+ declare abstract class Adapter {
71
+ abstract getExamples<TInput, TOutput>(props: GetExamplesProps<TInput>): Promise<Array<{
72
+ key: string;
73
+ input: TInput;
74
+ output: TOutput;
75
+ explanation?: string;
76
+ similarity: number;
77
+ }>>;
78
+ abstract saveExample<TInput, TOutput>(props: SaveExampleProps<TInput, TOutput>): Promise<void>;
79
+ }
80
+
81
+ declare const Models: readonly [{
82
+ readonly id: "anthropic__claude-3-haiku-20240307";
83
+ readonly name: "Claude 3 Haiku";
84
+ readonly integration: "anthropic";
85
+ readonly input: {
86
+ readonly maxTokens: 200000;
87
+ };
88
+ readonly output: {
89
+ readonly maxTokens: 4096;
90
+ };
91
+ }, {
92
+ readonly id: "anthropic__claude-3-5-sonnet-20240620";
93
+ readonly name: "Claude 3.5 Sonnet";
94
+ readonly integration: "anthropic";
95
+ readonly input: {
96
+ readonly maxTokens: 200000;
97
+ };
98
+ readonly output: {
99
+ readonly maxTokens: 4096;
100
+ };
101
+ }, {
102
+ readonly id: "cerebras__llama3.1-70b";
103
+ readonly name: "Llama 3.1 70B";
104
+ readonly integration: "cerebras";
105
+ readonly input: {
106
+ readonly maxTokens: 8192;
107
+ };
108
+ readonly output: {
109
+ readonly maxTokens: 8192;
110
+ };
111
+ }, {
112
+ readonly id: "cerebras__llama3.1-8b";
113
+ readonly name: "Llama 3.1 8B";
114
+ readonly integration: "cerebras";
115
+ readonly input: {
116
+ readonly maxTokens: 8192;
117
+ };
118
+ readonly output: {
119
+ readonly maxTokens: 8192;
120
+ };
121
+ }, {
122
+ readonly id: "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct";
123
+ readonly name: "DeepSeek Coder V2 Instruct";
124
+ readonly integration: "fireworks-ai";
125
+ readonly input: {
126
+ readonly maxTokens: 131072;
127
+ };
128
+ readonly output: {
129
+ readonly maxTokens: 131072;
130
+ };
131
+ }, {
132
+ readonly id: "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct";
133
+ readonly name: "DeepSeek Coder V2 Lite";
134
+ readonly integration: "fireworks-ai";
135
+ readonly input: {
136
+ readonly maxTokens: 163840;
137
+ };
138
+ readonly output: {
139
+ readonly maxTokens: 163840;
140
+ };
141
+ }, {
142
+ readonly id: "fireworks-ai__accounts/fireworks/models/firellava-13b";
143
+ readonly name: "FireLLaVA-13B";
144
+ readonly integration: "fireworks-ai";
145
+ readonly input: {
146
+ readonly maxTokens: 4096;
147
+ };
148
+ readonly output: {
149
+ readonly maxTokens: 4096;
150
+ };
151
+ }, {
152
+ readonly id: "fireworks-ai__accounts/fireworks/models/firefunction-v2";
153
+ readonly name: "Firefunction V2";
154
+ readonly integration: "fireworks-ai";
155
+ readonly input: {
156
+ readonly maxTokens: 8192;
157
+ };
158
+ readonly output: {
159
+ readonly maxTokens: 8192;
160
+ };
161
+ }, {
162
+ readonly id: "fireworks-ai__accounts/fireworks/models/gemma2-9b-it";
163
+ readonly name: "Gemma 2 9B Instruct";
164
+ readonly integration: "fireworks-ai";
165
+ readonly input: {
166
+ readonly maxTokens: 8192;
167
+ };
168
+ readonly output: {
169
+ readonly maxTokens: 8192;
170
+ };
171
+ }, {
172
+ readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct";
173
+ readonly name: "Llama 3.1 405B Instruct";
174
+ readonly integration: "fireworks-ai";
175
+ readonly input: {
176
+ readonly maxTokens: 131072;
177
+ };
178
+ readonly output: {
179
+ readonly maxTokens: 131072;
180
+ };
181
+ }, {
182
+ readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct";
183
+ readonly name: "Llama 3.1 70B Instruct";
184
+ readonly integration: "fireworks-ai";
185
+ readonly input: {
186
+ readonly maxTokens: 131072;
187
+ };
188
+ readonly output: {
189
+ readonly maxTokens: 131072;
190
+ };
191
+ }, {
192
+ readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct";
193
+ readonly name: "Llama 3.1 8B Instruct";
194
+ readonly integration: "fireworks-ai";
195
+ readonly input: {
196
+ readonly maxTokens: 131072;
197
+ };
198
+ readonly output: {
199
+ readonly maxTokens: 131072;
200
+ };
201
+ }, {
202
+ readonly id: "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct";
203
+ readonly name: "Mixtral MoE 8x22B Instruct";
204
+ readonly integration: "fireworks-ai";
205
+ readonly input: {
206
+ readonly maxTokens: 65536;
207
+ };
208
+ readonly output: {
209
+ readonly maxTokens: 65536;
210
+ };
211
+ }, {
212
+ readonly id: "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct";
213
+ readonly name: "Mixtral MoE 8x7B Instruct";
214
+ readonly integration: "fireworks-ai";
215
+ readonly input: {
216
+ readonly maxTokens: 32768;
217
+ };
218
+ readonly output: {
219
+ readonly maxTokens: 32768;
220
+ };
221
+ }, {
222
+ readonly id: "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b";
223
+ readonly name: "MythoMax L2 13b";
224
+ readonly integration: "fireworks-ai";
225
+ readonly input: {
226
+ readonly maxTokens: 4096;
227
+ };
228
+ readonly output: {
229
+ readonly maxTokens: 4096;
230
+ };
231
+ }, {
232
+ readonly id: "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct";
233
+ readonly name: "Qwen2 72b Instruct";
234
+ readonly integration: "fireworks-ai";
235
+ readonly input: {
236
+ readonly maxTokens: 32768;
237
+ };
238
+ readonly output: {
239
+ readonly maxTokens: 32768;
240
+ };
241
+ }, {
242
+ readonly id: "groq__gemma2-9b-it";
243
+ readonly name: "Gemma2 9B";
244
+ readonly integration: "groq";
245
+ readonly input: {
246
+ readonly maxTokens: 8192;
247
+ };
248
+ readonly output: {
249
+ readonly maxTokens: 8192;
250
+ };
251
+ }, {
252
+ readonly id: "groq__llama3-70b-8192";
253
+ readonly name: "LLaMA 3 70B";
254
+ readonly integration: "groq";
255
+ readonly input: {
256
+ readonly maxTokens: 8192;
257
+ };
258
+ readonly output: {
259
+ readonly maxTokens: 8192;
260
+ };
261
+ }, {
262
+ readonly id: "groq__llama3-8b-8192";
263
+ readonly name: "LLaMA 3 8B";
264
+ readonly integration: "groq";
265
+ readonly input: {
266
+ readonly maxTokens: 8192;
267
+ };
268
+ readonly output: {
269
+ readonly maxTokens: 8192;
270
+ };
271
+ }, {
272
+ readonly id: "groq__llama-3.1-70b-versatile";
273
+ readonly name: "LLaMA 3.1 70B";
274
+ readonly integration: "groq";
275
+ readonly input: {
276
+ readonly maxTokens: 128000;
277
+ };
278
+ readonly output: {
279
+ readonly maxTokens: 8192;
280
+ };
281
+ }, {
282
+ readonly id: "groq__llama-3.1-8b-instant";
283
+ readonly name: "LLaMA 3.1 8B";
284
+ readonly integration: "groq";
285
+ readonly input: {
286
+ readonly maxTokens: 128000;
287
+ };
288
+ readonly output: {
289
+ readonly maxTokens: 8192;
290
+ };
291
+ }, {
292
+ readonly id: "groq__llama-3.2-11b-vision-preview";
293
+ readonly name: "LLaMA 3.2 11B Vision";
294
+ readonly integration: "groq";
295
+ readonly input: {
296
+ readonly maxTokens: 128000;
297
+ };
298
+ readonly output: {
299
+ readonly maxTokens: 8192;
300
+ };
301
+ }, {
302
+ readonly id: "groq__llama-3.2-1b-preview";
303
+ readonly name: "LLaMA 3.2 1B";
304
+ readonly integration: "groq";
305
+ readonly input: {
306
+ readonly maxTokens: 128000;
307
+ };
308
+ readonly output: {
309
+ readonly maxTokens: 8192;
310
+ };
311
+ }, {
312
+ readonly id: "groq__llama-3.2-3b-preview";
313
+ readonly name: "LLaMA 3.2 3B";
314
+ readonly integration: "groq";
315
+ readonly input: {
316
+ readonly maxTokens: 128000;
317
+ };
318
+ readonly output: {
319
+ readonly maxTokens: 8192;
320
+ };
321
+ }, {
322
+ readonly id: "groq__llama-3.2-90b-vision-preview";
323
+ readonly name: "LLaMA 3.2 90B Vision";
324
+ readonly integration: "groq";
325
+ readonly input: {
326
+ readonly maxTokens: 128000;
327
+ };
328
+ readonly output: {
329
+ readonly maxTokens: 8192;
330
+ };
331
+ }, {
332
+ readonly id: "groq__llama-3.3-70b-versatile";
333
+ readonly name: "LLaMA 3.3 70B";
334
+ readonly integration: "groq";
335
+ readonly input: {
336
+ readonly maxTokens: 128000;
337
+ };
338
+ readonly output: {
339
+ readonly maxTokens: 32768;
340
+ };
341
+ }, {
342
+ readonly id: "groq__mixtral-8x7b-32768";
343
+ readonly name: "Mixtral 8x7B";
344
+ readonly integration: "groq";
345
+ readonly input: {
346
+ readonly maxTokens: 32768;
347
+ };
348
+ readonly output: {
349
+ readonly maxTokens: 32768;
350
+ };
351
+ }, {
352
+ readonly id: "openai__o1-2024-12-17";
353
+ readonly name: "GPT o1";
354
+ readonly integration: "openai";
355
+ readonly input: {
356
+ readonly maxTokens: 200000;
357
+ };
358
+ readonly output: {
359
+ readonly maxTokens: 100000;
360
+ };
361
+ }, {
362
+ readonly id: "openai__o1-mini-2024-09-12";
363
+ readonly name: "GPT o1-mini";
364
+ readonly integration: "openai";
365
+ readonly input: {
366
+ readonly maxTokens: 128000;
367
+ };
368
+ readonly output: {
369
+ readonly maxTokens: 65536;
370
+ };
371
+ }, {
372
+ readonly id: "openai__gpt-3.5-turbo-0125";
373
+ readonly name: "GPT-3.5 Turbo";
374
+ readonly integration: "openai";
375
+ readonly input: {
376
+ readonly maxTokens: 128000;
377
+ };
378
+ readonly output: {
379
+ readonly maxTokens: 4096;
380
+ };
381
+ }, {
382
+ readonly id: "openai__gpt-4-turbo-2024-04-09";
383
+ readonly name: "GPT-4 Turbo";
384
+ readonly integration: "openai";
385
+ readonly input: {
386
+ readonly maxTokens: 128000;
387
+ };
388
+ readonly output: {
389
+ readonly maxTokens: 4096;
390
+ };
391
+ }, {
392
+ readonly id: "openai__gpt-4o-2024-08-06";
393
+ readonly name: "GPT-4o (August 2024)";
394
+ readonly integration: "openai";
395
+ readonly input: {
396
+ readonly maxTokens: 128000;
397
+ };
398
+ readonly output: {
399
+ readonly maxTokens: 16384;
400
+ };
401
+ }, {
402
+ readonly id: "openai__gpt-4o-2024-05-13";
403
+ readonly name: "GPT-4o (May 2024)";
404
+ readonly integration: "openai";
405
+ readonly input: {
406
+ readonly maxTokens: 128000;
407
+ };
408
+ readonly output: {
409
+ readonly maxTokens: 4096;
410
+ };
411
+ }, {
412
+ readonly id: "openai__gpt-4o-2024-11-20";
413
+ readonly name: "GPT-4o (November 2024)";
414
+ readonly integration: "openai";
415
+ readonly input: {
416
+ readonly maxTokens: 128000;
417
+ };
418
+ readonly output: {
419
+ readonly maxTokens: 16384;
420
+ };
421
+ }, {
422
+ readonly id: "openai__gpt-4o-mini-2024-07-18";
423
+ readonly name: "GPT-4o Mini";
424
+ readonly integration: "openai";
425
+ readonly input: {
426
+ readonly maxTokens: 128000;
427
+ };
428
+ readonly output: {
429
+ readonly maxTokens: 16384;
430
+ };
431
+ }];
432
+
433
+ declare namespace llm {
434
+ namespace generateContent {
435
+ type Input = {
436
+ /** Model to use for content generation */
437
+ model?: {
438
+ id: string;
439
+ };
440
+ /** Optional system prompt to guide the model */
441
+ systemPrompt?: string;
442
+ /** Array of messages for the model to process */
443
+ messages: Array<{
444
+ role: 'user' | 'assistant';
445
+ type?: 'text' | 'tool_calls' | 'tool_result' | 'multipart';
446
+ /** Required if `type` is "tool_calls" */
447
+ toolCalls?: Array<{
448
+ id: string;
449
+ type: 'function';
450
+ function: {
451
+ name: string;
452
+ /** Some LLMs may generate invalid JSON for a tool call, so this will be `null` when it happens. */
453
+ arguments: {
454
+ [key: string]: any;
455
+ } | null;
456
+ };
457
+ }>;
458
+ /** Required if `type` is "tool_result" */
459
+ toolResultCallId?: string;
460
+ /** Required unless `type` is "tool_call". If `type` is "multipart", this field must be an array of content objects. If `type` is "tool_result" then this field should be the result of the tool call (a plain string or a JSON-encoded array or object). If `type` is "tool_call" then the `toolCalls` field should be used instead. */
461
+ content: string | Array<{
462
+ type: 'text' | 'image';
463
+ /** Indicates the MIME type of the content. If not provided it will be detected from the content-type header of the provided URL. */
464
+ mimeType?: string;
465
+ /** Required if part type is "text" */
466
+ text?: string;
467
+ /** Required if part type is "image" */
468
+ url?: string;
469
+ }> | null;
470
+ }>;
471
+ /** Response format expected from the model. If "json_object" is chosen, you must instruct the model to generate JSON either via the system prompt or a user message. */
472
+ responseFormat?: 'text' | 'json_object';
473
+ /** Maximum number of tokens allowed in the generated response */
474
+ maxTokens?: number;
475
+ /** Sampling temperature for the model. Higher values result in more random outputs. */
476
+ temperature?: number;
477
+ /** Top-p sampling parameter. Limits sampling to the smallest set of tokens with a cumulative probability above the threshold. */
478
+ topP?: number;
479
+ /** Sequences where the model should stop generating further tokens. */
480
+ stopSequences?: string[];
481
+ tools?: Array<{
482
+ type: 'function';
483
+ function: {
484
+ /** Function name */
485
+ name: string;
486
+ description?: string;
487
+ /** JSON schema of the function arguments */
488
+ argumentsSchema?: {};
489
+ };
490
+ }>;
491
+ toolChoice?: {
492
+ type?: 'auto' | 'specific' | 'any' | 'none' | '';
493
+ /** Required if `type` is "specific" */
494
+ functionName?: string;
495
+ };
496
+ userId?: string;
497
+ /** Set to `true` to output debug information to the bot logs */
498
+ debug?: boolean;
499
+ meta?: {
500
+ /** Source of the prompt, e.g. agent/:id/:version cards/ai-generate, cards/ai-task, nodes/autonomous, etc. */
501
+ promptSource?: string;
502
+ promptCategory?: string;
503
+ /** Name of the integration that originally received the message that initiated this action */
504
+ integrationName?: string;
505
+ };
506
+ };
507
+ type Output = {
508
+ /** Response ID from LLM provider */
509
+ id: string;
510
+ /** LLM provider name */
511
+ provider: string;
512
+ /** Model name */
513
+ model: string;
514
+ choices: Array<{
515
+ type?: 'text' | 'tool_calls' | 'tool_result' | 'multipart';
516
+ /** Required if `type` is "tool_calls" */
517
+ toolCalls?: Array<{
518
+ id: string;
519
+ type: 'function';
520
+ function: {
521
+ name: string;
522
+ /** Some LLMs may generate invalid JSON for a tool call, so this will be `null` when it happens. */
523
+ arguments: {
524
+ [key: string]: any;
525
+ } | null;
526
+ };
527
+ }>;
528
+ /** Required if `type` is "tool_result" */
529
+ toolResultCallId?: string;
530
+ /** Required unless `type` is "tool_call". If `type` is "multipart", this field must be an array of content objects. If `type` is "tool_result" then this field should be the result of the tool call (a plain string or a JSON-encoded array or object). If `type` is "tool_call" then the `toolCalls` field should be used instead. */
531
+ content: string | Array<{
532
+ type: 'text' | 'image';
533
+ /** Indicates the MIME type of the content. If not provided it will be detected from the content-type header of the provided URL. */
534
+ mimeType?: string;
535
+ /** Required if part type is "text" */
536
+ text?: string;
537
+ /** Required if part type is "image" */
538
+ url?: string;
539
+ }> | null;
540
+ role: 'assistant';
541
+ index: number;
542
+ stopReason: 'stop' | 'max_tokens' | 'tool_calls' | 'content_filter' | 'other';
543
+ }>;
544
+ usage: {
545
+ /** Number of input tokens used by the model */
546
+ inputTokens: number;
547
+ /** Cost of the input tokens received by the model, in U.S. dollars */
548
+ inputCost: number;
549
+ /** Number of output tokens used by the model */
550
+ outputTokens: number;
551
+ /** Cost of the output tokens generated by the model, in U.S. dollars */
552
+ outputCost: number;
553
+ };
554
+ botpress: {
555
+ /** Total cost of the content generation, in U.S. dollars */
556
+ cost: number;
557
+ };
558
+ };
559
+ }
560
+ }
561
+
562
+ type ActiveLearning = z.input<typeof ActiveLearning>;
563
+ declare const ActiveLearning: _bpinternal_zui.ZodObject<{
564
+ enable: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodBoolean>;
565
+ tableName: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
566
+ taskId: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
567
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
568
+ tableName?: string;
569
+ taskId?: string;
570
+ enable?: boolean;
571
+ }, {
572
+ tableName?: string;
573
+ taskId?: string;
574
+ enable?: boolean;
575
+ }>;
576
+ type ZaiConfig = z.input<typeof ZaiConfig>;
577
+ declare const ZaiConfig: _bpinternal_zui.ZodObject<{
578
+ client: z.Schema<any, _bpinternal_zui.ZodTypeDef, any>;
579
+ userId: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
580
+ retry: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodObject<{
581
+ maxRetries: _bpinternal_zui.ZodNumber;
582
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
583
+ maxRetries?: number;
584
+ }, {
585
+ maxRetries?: number;
586
+ }>>;
587
+ modelId: _bpinternal_zui.ZodDefault<z.Schema<string, _bpinternal_zui.ZodTypeDef, string>>;
588
+ activeLearning: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodObject<{
589
+ enable: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodBoolean>;
590
+ tableName: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
591
+ taskId: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
592
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
593
+ tableName?: string;
594
+ taskId?: string;
595
+ enable?: boolean;
596
+ }, {
597
+ tableName?: string;
598
+ taskId?: string;
599
+ enable?: boolean;
600
+ }>>;
601
+ namespace: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
602
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
603
+ client?: any;
604
+ userId?: string;
605
+ retry?: {
606
+ maxRetries?: number;
607
+ };
608
+ modelId?: string;
609
+ activeLearning?: {
610
+ tableName?: string;
611
+ taskId?: string;
612
+ enable?: boolean;
613
+ };
614
+ namespace?: string;
615
+ }, {
616
+ client?: any;
617
+ userId?: string;
618
+ retry?: {
619
+ maxRetries?: number;
620
+ };
621
+ modelId?: string;
622
+ activeLearning?: {
623
+ tableName?: string;
624
+ taskId?: string;
625
+ enable?: boolean;
626
+ };
627
+ namespace?: string;
628
+ }>;
629
+ declare class Zai {
630
+ protected static tokenizer: TextTokenizer;
631
+ protected client: Client;
632
+ private originalConfig;
633
+ private userId;
634
+ private integration;
635
+ private model;
636
+ private retry;
637
+ protected Model: (typeof Models)[number];
638
+ protected namespace: string;
639
+ protected adapter: Adapter;
640
+ protected activeLearning: ActiveLearning;
641
+ constructor(config: ZaiConfig);
642
+ /** @internal */
643
+ protected callModel(props: Partial<llm.generateContent.Input>): Promise<llm.generateContent.Output & {
644
+ metadata: GenerationMetadata;
645
+ }>;
646
+ /** @internal */
647
+ private _callModel;
648
+ protected getTokenizer(): Promise<TextTokenizer>;
649
+ protected get taskId(): string;
650
+ with(options: Partial<ZaiConfig>): Zai;
651
+ learn(taskId: string): Zai;
652
+ }
653
+
654
+ type Options$6 = z.input<typeof Options$6>;
655
+ declare const Options$6: _bpinternal_zui.ZodObject<{
656
+ length: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>;
657
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
658
+ length?: number;
659
+ }, {
660
+ length?: number;
661
+ }>;
662
+ declare module '@botpress/zai' {
663
+ interface Zai {
664
+ /** Generates a text of the desired length according to the prompt */
665
+ text(prompt: string, options?: Options$6): Promise<string>;
666
+ }
667
+ }
668
+
669
+ type Options$5 = z.input<typeof Options$5>;
670
+ declare const Options$5: _bpinternal_zui.ZodObject<{
671
+ examples: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodArray<_bpinternal_zui.ZodObject<{
672
+ input: _bpinternal_zui.ZodString;
673
+ output: _bpinternal_zui.ZodString;
674
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
675
+ input?: string;
676
+ output?: string;
677
+ }, {
678
+ input?: string;
679
+ output?: string;
680
+ }>, "many">>;
681
+ length: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>;
682
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
683
+ length?: number;
684
+ examples?: {
685
+ input?: string;
686
+ output?: string;
687
+ }[];
688
+ }, {
689
+ length?: number;
690
+ examples?: {
691
+ input?: string;
692
+ output?: string;
693
+ }[];
694
+ }>;
695
+ declare module '@botpress/zai' {
696
+ interface Zai {
697
+ /** Rewrites a string according to match the prompt */
698
+ rewrite(original: string, prompt: string, options?: Options$5): Promise<string>;
699
+ }
700
+ }
701
+
702
+ type Options$4 = z.input<typeof Options$4>;
703
+ declare const Options$4: _bpinternal_zui.ZodObject<{
704
+ prompt: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
705
+ format: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
706
+ length: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodNumber>;
707
+ intermediateFactor: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodNumber>;
708
+ maxIterations: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodNumber>;
709
+ sliding: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodObject<{
710
+ window: _bpinternal_zui.ZodNumber;
711
+ overlap: _bpinternal_zui.ZodNumber;
712
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
713
+ window?: number;
714
+ overlap?: number;
715
+ }, {
716
+ window?: number;
717
+ overlap?: number;
718
+ }>>;
719
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
720
+ length?: number;
721
+ prompt?: string;
722
+ format?: string;
723
+ intermediateFactor?: number;
724
+ maxIterations?: number;
725
+ sliding?: {
726
+ window?: number;
727
+ overlap?: number;
728
+ };
729
+ }, {
730
+ length?: number;
731
+ prompt?: string;
732
+ format?: string;
733
+ intermediateFactor?: number;
734
+ maxIterations?: number;
735
+ sliding?: {
736
+ window?: number;
737
+ overlap?: number;
738
+ };
739
+ }>;
740
+ declare module '@botpress/zai' {
741
+ interface Zai {
742
+ /** Summarizes a text of any length to a summary of the desired length */
743
+ summarize(original: string, options?: Options$4): Promise<string>;
744
+ }
745
+ }
746
+
747
+ type Options$3 = z.input<typeof Options$3>;
748
+ declare const Options$3: _bpinternal_zui.ZodObject<{
749
+ examples: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodArray<_bpinternal_zui.ZodObject<{
750
+ input: _bpinternal_zui.ZodAny;
751
+ check: _bpinternal_zui.ZodBoolean;
752
+ reason: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
753
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
754
+ input?: any;
755
+ check?: boolean;
756
+ reason?: string;
757
+ }, {
758
+ input?: any;
759
+ check?: boolean;
760
+ reason?: string;
761
+ }>, "many">>;
762
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
763
+ examples?: {
764
+ input?: any;
765
+ check?: boolean;
766
+ reason?: string;
767
+ }[];
768
+ }, {
769
+ examples?: {
770
+ input?: any;
771
+ check?: boolean;
772
+ reason?: string;
773
+ }[];
774
+ }>;
775
+ declare module '@botpress/zai' {
776
+ interface Zai {
777
+ /** Checks wether a condition is true or not */
778
+ check(input: unknown, condition: string, options?: Options$3): Promise<boolean>;
779
+ }
780
+ }
781
+
782
+ type Options$2 = z.input<typeof Options$2>;
783
+ declare const Options$2: _bpinternal_zui.ZodObject<{
784
+ tokensPerItem: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>>;
785
+ examples: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodArray<_bpinternal_zui.ZodObject<{
786
+ input: _bpinternal_zui.ZodAny;
787
+ filter: _bpinternal_zui.ZodBoolean;
788
+ reason: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
789
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
790
+ input?: any;
791
+ filter?: boolean;
792
+ reason?: string;
793
+ }, {
794
+ input?: any;
795
+ filter?: boolean;
796
+ reason?: string;
797
+ }>, "many">>;
798
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
799
+ examples?: {
800
+ input?: any;
801
+ filter?: boolean;
802
+ reason?: string;
803
+ }[];
804
+ tokensPerItem?: number;
805
+ }, {
806
+ examples?: {
807
+ input?: any;
808
+ filter?: boolean;
809
+ reason?: string;
810
+ }[];
811
+ tokensPerItem?: number;
812
+ }>;
813
+ declare module '@botpress/zai' {
814
+ interface Zai {
815
+ /** Filters elements of an array against a condition */
816
+ filter<T>(input: Array<T>, condition: string, options?: Options$2): Promise<Array<T>>;
817
+ }
818
+ }
819
+
820
+ type Options$1 = z.input<typeof Options$1>;
821
+ declare const Options$1: _bpinternal_zui.ZodObject<{
822
+ instructions: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
823
+ chunkLength: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>>;
824
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
825
+ instructions?: string;
826
+ chunkLength?: number;
827
+ }, {
828
+ instructions?: string;
829
+ chunkLength?: number;
830
+ }>;
831
+ declare module '@botpress/zai' {
832
+ interface Zai {
833
+ /** Extracts one or many elements from an arbitrary input */
834
+ extract<S extends z.AnyZodObject>(input: unknown, schema: S, options?: Options$1): Promise<z.infer<S>>;
835
+ extract<S extends z.AnyZodObject>(input: unknown, schema: z.ZodArray<S>, options?: Options$1): Promise<Array<z.infer<S>>>;
836
+ }
837
+ }
838
+
839
+ type Label = keyof typeof LABELS;
840
+ declare const LABELS: {
841
+ readonly ABSOLUTELY_NOT: "ABSOLUTELY_NOT";
842
+ readonly PROBABLY_NOT: "PROBABLY_NOT";
843
+ readonly AMBIGUOUS: "AMBIGUOUS";
844
+ readonly PROBABLY_YES: "PROBABLY_YES";
845
+ readonly ABSOLUTELY_YES: "ABSOLUTELY_YES";
846
+ };
847
+ type Example<T extends string> = {
848
+ input: unknown;
849
+ labels: Partial<Record<T, {
850
+ label: Label;
851
+ explanation?: string;
852
+ }>>;
853
+ };
854
+ type Options<T extends string> = Omit<z.input<typeof Options>, 'examples'> & {
855
+ examples?: Array<Partial<Example<T>>>;
856
+ };
857
+ declare const Options: _bpinternal_zui.ZodObject<{
858
+ examples: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodArray<_bpinternal_zui.ZodObject<{
859
+ input: _bpinternal_zui.ZodAny;
860
+ labels: _bpinternal_zui.ZodRecord<_bpinternal_zui.ZodString, _bpinternal_zui.ZodObject<{
861
+ label: _bpinternal_zui.ZodEnum<never>;
862
+ explanation: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
863
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
864
+ label: never;
865
+ explanation?: string;
866
+ }, {
867
+ label: never;
868
+ explanation?: string;
869
+ }>>;
870
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
871
+ input?: any;
872
+ labels?: Record<string, {
873
+ label: never;
874
+ explanation?: string;
875
+ }>;
876
+ }, {
877
+ input?: any;
878
+ labels?: Record<string, {
879
+ label: never;
880
+ explanation?: string;
881
+ }>;
882
+ }>, "many">>;
883
+ instructions: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
884
+ chunkLength: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>>;
885
+ }, "strip", _bpinternal_zui.ZodTypeAny, {
886
+ instructions?: string;
887
+ examples?: {
888
+ input?: any;
889
+ labels?: Record<string, {
890
+ label: never;
891
+ explanation?: string;
892
+ }>;
893
+ }[];
894
+ chunkLength?: number;
895
+ }, {
896
+ instructions?: string;
897
+ examples?: {
898
+ input?: any;
899
+ labels?: Record<string, {
900
+ label: never;
901
+ explanation?: string;
902
+ }>;
903
+ }[];
904
+ chunkLength?: number;
905
+ }>;
906
+ type Labels<T extends string> = Record<T, string>;
907
+ declare const Labels: z.ZodTransformer<_bpinternal_zui.ZodRecord<_bpinternal_zui.ZodString, _bpinternal_zui.ZodString>, Record<string, string>, Record<string, string>>;
908
+ declare module '@botpress/zai' {
909
+ interface Zai {
910
+ /** Tags the provided input with a list of predefined labels */
911
+ label<T extends string>(input: unknown, labels: Labels<T>, options?: Options<T>): Promise<{
912
+ [K in T]: boolean;
913
+ }>;
914
+ }
915
+ }
916
+
917
+ export { Zai };