@botpress/zai 1.1.0 → 1.2.0

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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
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';
2
+ import { z, ZodObject } from '@bpinternal/zui';
3
+ import { Cognitive, Model, BotpressClientLike } from '@botpress/cognitive';
4
+ import { TextTokenizer } from '@bpinternal/thicktoken';
5
5
 
6
6
  type GenerationMetadata = z.input<typeof GenerationMetadata>;
7
7
  declare const GenerationMetadata: _bpinternal_zui.ZodObject<{
@@ -33,22 +33,22 @@ declare const GenerationMetadata: _bpinternal_zui.ZodObject<{
33
33
  input?: number;
34
34
  output?: number;
35
35
  };
36
- latency?: number;
37
36
  tokens?: {
38
37
  input?: number;
39
38
  output?: number;
40
39
  };
40
+ latency?: number;
41
41
  }, {
42
42
  model?: string;
43
43
  cost?: {
44
44
  input?: number;
45
45
  output?: number;
46
46
  };
47
- latency?: number;
48
47
  tokens?: {
49
48
  input?: number;
50
49
  output?: number;
51
50
  };
51
+ latency?: number;
52
52
  }>;
53
53
 
54
54
  type SaveExampleProps<TInput, TOutput> = {
@@ -78,487 +78,7 @@ declare abstract class Adapter {
78
78
  abstract saveExample<TInput, TOutput>(props: SaveExampleProps<TInput, TOutput>): Promise<void>;
79
79
  }
80
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
-
81
+ type ModelId = Required<Parameters<Cognitive['generateContent']>[0]['model']>;
562
82
  type ActiveLearning = z.input<typeof ActiveLearning>;
563
83
  declare const ActiveLearning: _bpinternal_zui.ZodObject<{
564
84
  enable: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodBoolean>;
@@ -575,15 +95,8 @@ declare const ActiveLearning: _bpinternal_zui.ZodObject<{
575
95
  }>;
576
96
  type ZaiConfig = z.input<typeof ZaiConfig>;
577
97
  declare const ZaiConfig: _bpinternal_zui.ZodObject<{
578
- client: z.Schema<any, _bpinternal_zui.ZodTypeDef, any>;
98
+ client: z.Schema<Cognitive | BotpressClientLike, _bpinternal_zui.ZodTypeDef, Cognitive | BotpressClientLike>;
579
99
  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
100
  modelId: _bpinternal_zui.ZodDefault<z.Schema<string, _bpinternal_zui.ZodTypeDef, string>>;
588
101
  activeLearning: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodObject<{
589
102
  enable: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodBoolean>;
@@ -600,11 +113,8 @@ declare const ZaiConfig: _bpinternal_zui.ZodObject<{
600
113
  }>>;
601
114
  namespace: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodString>;
602
115
  }, "strip", _bpinternal_zui.ZodTypeAny, {
603
- client?: any;
604
116
  userId?: string;
605
- retry?: {
606
- maxRetries?: number;
607
- };
117
+ client?: Cognitive | BotpressClientLike;
608
118
  modelId?: string;
609
119
  activeLearning?: {
610
120
  tableName?: string;
@@ -613,11 +123,8 @@ declare const ZaiConfig: _bpinternal_zui.ZodObject<{
613
123
  };
614
124
  namespace?: string;
615
125
  }, {
616
- client?: any;
617
126
  userId?: string;
618
- retry?: {
619
- maxRetries?: number;
620
- };
127
+ client?: Cognitive | BotpressClientLike;
621
128
  modelId?: string;
622
129
  activeLearning?: {
623
130
  tableName?: string;
@@ -628,24 +135,19 @@ declare const ZaiConfig: _bpinternal_zui.ZodObject<{
628
135
  }>;
629
136
  declare class Zai {
630
137
  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];
138
+ protected client: Cognitive;
139
+ private _originalConfig;
140
+ private _userId;
141
+ protected Model: ModelId;
142
+ protected ModelDetails: Model;
638
143
  protected namespace: string;
639
144
  protected adapter: Adapter;
640
145
  protected activeLearning: ActiveLearning;
641
146
  constructor(config: ZaiConfig);
642
147
  /** @internal */
643
- protected callModel(props: Partial<llm.generateContent.Input>): Promise<llm.generateContent.Output & {
644
- metadata: GenerationMetadata;
645
- }>;
646
- /** @internal */
647
- private _callModel;
148
+ protected callModel(props: Parameters<Cognitive['generateContent']>[0]): ReturnType<Cognitive['generateContent']>;
648
149
  protected getTokenizer(): Promise<TextTokenizer>;
150
+ protected fetchModelDetails(): Promise<void>;
649
151
  protected get taskId(): string;
650
152
  with(options: Partial<ZaiConfig>): Zai;
651
153
  learn(taskId: string): Zai;
@@ -787,25 +289,25 @@ declare const Options$2: _bpinternal_zui.ZodObject<{
787
289
  filter: _bpinternal_zui.ZodBoolean;
788
290
  reason: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
789
291
  }, "strip", _bpinternal_zui.ZodTypeAny, {
790
- input?: any;
791
292
  filter?: boolean;
293
+ input?: any;
792
294
  reason?: string;
793
295
  }, {
794
- input?: any;
795
296
  filter?: boolean;
297
+ input?: any;
796
298
  reason?: string;
797
299
  }>, "many">>;
798
300
  }, "strip", _bpinternal_zui.ZodTypeAny, {
799
301
  examples?: {
800
- input?: any;
801
302
  filter?: boolean;
303
+ input?: any;
802
304
  reason?: string;
803
305
  }[];
804
306
  tokensPerItem?: number;
805
307
  }, {
806
308
  examples?: {
807
- input?: any;
808
309
  filter?: boolean;
310
+ input?: any;
809
311
  reason?: string;
810
312
  }[];
811
313
  tokensPerItem?: number;
@@ -818,7 +320,7 @@ declare module '@botpress/zai' {
818
320
  }
819
321
 
820
322
  type Options$1 = z.input<typeof Options$1>;
821
- declare const Options$1: _bpinternal_zui.ZodObject<{
323
+ declare const Options$1: ZodObject<{
822
324
  instructions: _bpinternal_zui.ZodOptional<_bpinternal_zui.ZodString>;
823
325
  chunkLength: _bpinternal_zui.ZodDefault<_bpinternal_zui.ZodOptional<_bpinternal_zui.ZodNumber>>;
824
326
  }, "strip", _bpinternal_zui.ZodTypeAny, {
@@ -831,8 +333,7 @@ declare const Options$1: _bpinternal_zui.ZodObject<{
831
333
  declare module '@botpress/zai' {
832
334
  interface Zai {
833
335
  /** 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>>>;
336
+ extract<S extends z.AnyZodObject | z.ZodArray>(input: unknown, schema: S, options?: Options$1): Promise<z.TypeOf<S>>;
836
337
  }
837
338
  }
838
339
 
@@ -16,7 +16,8 @@ const END = "\u25A0END\u25A0";
16
16
  Zai.prototype.check = async function(input, condition, _options) {
17
17
  const options = Options.parse(_options ?? {});
18
18
  const tokenizer = await this.getTokenizer();
19
- const PROMPT_COMPONENT = Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100);
19
+ await this.fetchModelDetails();
20
+ const PROMPT_COMPONENT = Math.max(this.ModelDetails.input.maxTokens - PROMPT_INPUT_BUFFER, 100);
20
21
  const taskId = this.taskId;
21
22
  const taskType = "zai.check";
22
23
  const PROMPT_TOKENS = {
@@ -91,7 +92,7 @@ ${END}
91
92
  - When in doubt, ground your decision on the examples provided by the experts instead of your own intuition.
92
93
  - When no example is similar to the input, make sure to provide a clear justification for your decision while inferring the decision-making process from the examples provided by the experts.
93
94
  `.trim() : "";
94
- const output = await this.callModel({
95
+ const { output, meta } = await this.callModel({
95
96
  systemPrompt: `
96
97
  Check if the following condition is true or false for the given input. Before answering, make sure to read the input and the condition carefully.
97
98
  Justify your answer, then answer with either ${TRUE} or ${FALSE} at the very end, then add ${END} to finish the response.
@@ -132,7 +133,18 @@ In your "Analysis", please refer to the Expert Examples # to justify your decisi
132
133
  taskId,
133
134
  input: inputAsString,
134
135
  instructions: condition,
135
- metadata: output.metadata,
136
+ metadata: {
137
+ cost: {
138
+ input: meta.cost.input,
139
+ output: meta.cost.output
140
+ },
141
+ latency: meta.latency,
142
+ model: this.Model,
143
+ tokens: {
144
+ input: meta.tokens.input,
145
+ output: meta.tokens.output
146
+ }
147
+ },
136
148
  output: finalAnswer,
137
149
  explanation: answer.replace(TRUE, "").replace(FALSE, "").replace(END, "").replace("Final Answer:", "").trim()
138
150
  });