@botpress/vai 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -33,7 +33,7 @@ test('example', () => {
33
33
  check(
34
34
  {
35
35
  message: 'hello my friend',
36
- from: 'user'
36
+ from: 'user',
37
37
  },
38
38
  'is a greeting message'
39
39
  ).toBe(true)
@@ -48,13 +48,13 @@ Extracts from anything in input the requested Zui Schema:
48
48
  const person = z.object({
49
49
  name: z.string(),
50
50
  age: z.number().optional(),
51
- country: z.string().optional()
51
+ country: z.string().optional(),
52
52
  })
53
53
 
54
54
  extract('My name is Sylvain, I am 33 yo and live in Canada', person).toMatchObject({
55
55
  name: 'Sylvain',
56
56
  age: 33,
57
- country: 'Canada'
57
+ country: 'Canada',
58
58
  })
59
59
  ```
60
60
 
@@ -100,13 +100,13 @@ describe('learns from examples', () => {
100
100
  {
101
101
  expected: true,
102
102
  value: 'Rasa the chatbot framework',
103
- reason: 'Rasa is a chatbot framework, so it competes with Botpress'
103
+ reason: 'Rasa is a chatbot framework, so it competes with Botpress',
104
104
  },
105
105
  {
106
106
  expected: false,
107
107
  value: 'Rasa the coffee company',
108
- reason: 'Since Rasa is a coffee company, it does not compete with Botpress which is not in the coffee business'
109
- }
108
+ reason: 'Since Rasa is a coffee company, it does not compete with Botpress which is not in the coffee business',
109
+ },
110
110
  ]
111
111
 
112
112
  check('Voiceflow', 'is competitor', { examples }).toBe(true)
package/build.ts ADDED
@@ -0,0 +1,9 @@
1
+ import esbuild from 'esbuild'
2
+ import glob from 'glob'
3
+
4
+ const entryPoints = glob.sync('./src/**/*.ts')
5
+ void esbuild.build({
6
+ entryPoints,
7
+ platform: 'neutral',
8
+ outdir: './dist',
9
+ })
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { z } from "@bpinternal/zui";
3
2
  import { Context } from "../context";
4
3
  import { asyncExpect } from "../utils/asyncAssertion";
@@ -16,6 +15,7 @@ export function check(value, condition, options) {
16
15
  input: value
17
16
  });
18
17
  return {
18
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
19
19
  ...toAssertion(promise),
20
20
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
21
21
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import json5 from "json5";
3
2
  import { expect } from "vitest";
4
3
  import { getCurrentTest } from "vitest/suite";
@@ -21,7 +20,7 @@ ${stack}
21
20
  });
22
21
  try {
23
22
  expect((await promise).result).toMatchObject(obj);
24
- } catch (err) {
23
+ } catch {
25
24
  const newError = new Error();
26
25
  newError.stack = newStack;
27
26
  expect.getState().snapshotState.match({
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { Context } from "../context";
3
2
  import { asyncExpect } from "../utils/asyncAssertion";
4
3
  import { predictJson } from "../utils/predictJson";
@@ -19,6 +18,7 @@ ${options.description}
19
18
  input: value
20
19
  });
21
20
  return {
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
22
22
  ...toAssertion(promise),
23
23
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
24
24
  toMatchObject: (expected) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { z } from "@bpinternal/zui";
3
2
  import { Context } from "../context";
4
3
  import { asyncExpect } from "../utils/asyncAssertion";
@@ -54,6 +53,7 @@ You need to return an array of objects with the index and a boolean value indica
54
53
  };
55
54
  });
56
55
  return {
56
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
57
57
  ...toAssertion(promise),
58
58
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
59
59
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { z } from "@bpinternal/zui";
3
2
  import { Context } from "../context";
4
3
  import { asyncExpect } from "../utils/asyncAssertion";
@@ -24,6 +23,7 @@ Criteria: ${condition}`,
24
23
  };
25
24
  });
26
25
  return {
26
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
27
27
  ...toAssertion(promise),
28
28
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
29
29
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
package/dist/context.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { onTestFinished } from "vitest";
3
2
  import { getCurrentTest } from "vitest/suite";
4
3
  const getTestMetadata = () => {
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { getCurrentTest } from "vitest/suite";
3
2
  export const setEvaluator = (model) => {
4
3
  const test = getCurrentTest();
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { Context } from "../context";
3
2
  export const setupClient = (client) => {
4
3
  Context.setClient(client);
package/dist/index.d.ts CHANGED
@@ -1,39 +1,40 @@
1
1
  import * as _bpinternal_zui from '@bpinternal/zui';
2
2
  import { z, AnyZodObject } from '@bpinternal/zui';
3
3
  import { TestFunction } from 'vitest';
4
+ import { llm } from '@botpress/common';
4
5
  import { Client } from '@botpress/client';
5
6
 
6
7
  type ScenarioLike = z.infer<typeof ScenarioLike>;
7
8
  declare const ScenarioLike: _bpinternal_zui.ZodUnion<[_bpinternal_zui.ZodString, _bpinternal_zui.ZodObject<{
8
9
  name: _bpinternal_zui.ZodString;
9
- }, "passthrough", _bpinternal_zui.ZodTypeAny, _bpinternal_zui.objectOutputType<{
10
+ }, "passthrough", _bpinternal_zui.objectOutputType<{
10
11
  name: _bpinternal_zui.ZodString;
11
- }, _bpinternal_zui.ZodTypeAny, "passthrough">, _bpinternal_zui.objectInputType<{
12
+ }, "passthrough">, _bpinternal_zui.objectInputType<{
12
13
  name: _bpinternal_zui.ZodString;
13
- }, _bpinternal_zui.ZodTypeAny, "passthrough">>, _bpinternal_zui.ZodObject<{
14
+ }, "passthrough">>, _bpinternal_zui.ZodObject<{
14
15
  id: _bpinternal_zui.ZodString;
15
- }, "passthrough", _bpinternal_zui.ZodTypeAny, _bpinternal_zui.objectOutputType<{
16
+ }, "passthrough", _bpinternal_zui.objectOutputType<{
16
17
  id: _bpinternal_zui.ZodString;
17
- }, _bpinternal_zui.ZodTypeAny, "passthrough">, _bpinternal_zui.objectInputType<{
18
+ }, "passthrough">, _bpinternal_zui.objectInputType<{
18
19
  id: _bpinternal_zui.ZodString;
19
- }, _bpinternal_zui.ZodTypeAny, "passthrough">>]>;
20
+ }, "passthrough">>]>;
20
21
  declare function compare<T extends ReadonlyArray<ScenarioLike>>(name: string | Function, scenarios: T, fn?: TestFunction<{
21
22
  scenario: T[number];
22
23
  }>): void;
23
24
 
24
25
  type Input = z.infer<typeof Input>;
25
- declare const Input: _bpinternal_zui.ZodUnion<[_bpinternal_zui.ZodUnion<[_bpinternal_zui.ZodString, z.ZodTransformer<_bpinternal_zui.ZodObject<{}, "passthrough", _bpinternal_zui.ZodTypeAny, _bpinternal_zui.objectOutputType<{}, _bpinternal_zui.ZodTypeAny, "passthrough">, _bpinternal_zui.objectInputType<{}, _bpinternal_zui.ZodTypeAny, "passthrough">>, _bpinternal_zui.objectOutputType<{}, _bpinternal_zui.ZodTypeAny, "passthrough">, _bpinternal_zui.objectInputType<{}, _bpinternal_zui.ZodTypeAny, "passthrough">>]>, _bpinternal_zui.ZodArray<_bpinternal_zui.ZodAny, "many">]>;
26
+ declare const Input: _bpinternal_zui.ZodUnion<[_bpinternal_zui.ZodUnion<[_bpinternal_zui.ZodString, z.ZodTransformer<_bpinternal_zui.ZodObject<{}, "passthrough", _bpinternal_zui.objectOutputType<{}, "passthrough">, _bpinternal_zui.objectInputType<{}, "passthrough">>, _bpinternal_zui.objectOutputType<{}, "passthrough">, _bpinternal_zui.objectInputType<{}, "passthrough">>]>, _bpinternal_zui.ZodArray<_bpinternal_zui.ZodAny, "many">]>;
26
27
  type Output<T = any> = z.infer<typeof Output> & {
27
28
  result: T;
28
29
  };
29
30
  declare const Output: _bpinternal_zui.ZodObject<{
30
31
  reason: _bpinternal_zui.ZodString;
31
32
  result: _bpinternal_zui.ZodAny;
32
- }, "strip", _bpinternal_zui.ZodTypeAny, {
33
- reason: string;
33
+ }, "strip", {
34
+ reason?: string;
34
35
  result?: any;
35
36
  }, {
36
- reason: string;
37
+ reason?: string;
37
38
  result?: any;
38
39
  }>;
39
40
 
@@ -52,7 +53,7 @@ type CheckOptions<T> = {
52
53
  declare function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>): {
53
54
  toBe: (expected: boolean) => Promise<Output<boolean> | AsyncExpectError<boolean>>;
54
55
  toMatchInlineSnapshot: (expected?: string) => Promise<void | Output<boolean> | AsyncExpectError<boolean>>;
55
- then<TResult1 = Output<boolean>, TResult2 = never>(onfulfilled?: ((value: Output<boolean>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
56
+ then<TResult1 = Output<boolean>, TResult2 = never>(onfulfilled?: (value: Output<boolean>) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
56
57
  value: PromiseLike<boolean>;
57
58
  };
58
59
 
@@ -68,7 +69,7 @@ declare function extract<T extends Input, S extends AnyZodObject>(value: T, shap
68
69
  toBe: (expected: z.infer<S>) => Promise<Output<z.infer<S>> | AsyncExpectError<z.infer<S>>>;
69
70
  toMatchObject: (expected: Partial<z.infer<S>>) => Promise<Output<z.infer<S>> | AsyncExpectError<z.infer<S>>>;
70
71
  toMatchInlineSnapshot: (expected?: string) => Promise<void | Output<z.infer<S>> | AsyncExpectError<z.infer<S>>>;
71
- then<TResult1 = Output<z.infer<S>>, TResult2 = never>(onfulfilled?: ((value: Output<z.infer<S>>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
72
+ then<TResult1 = Output<z.infer<S>>, TResult2 = never>(onfulfilled?: (value: Output<z.infer<S>>) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
72
73
  value: PromiseLike<z.infer<S>>;
73
74
  };
74
75
 
@@ -91,7 +92,7 @@ declare function filter<U>(values: U[], condition: string, options?: FilterOptio
91
92
  toBeLessThanOrEqual: (expected: number) => Promise<Output<U[]> | AsyncExpectError<U[]>>;
92
93
  toBeBetween: (min: number, max: number) => Promise<Output<U[]> | AsyncExpectError<U[]>>;
93
94
  };
94
- then<TResult1 = Output<U[]>, TResult2 = never>(onfulfilled?: ((value: Output<U[]>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
95
+ then<TResult1 = Output<U[]>, TResult2 = never>(onfulfilled?: (value: Output<U[]>) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
95
96
  value: PromiseLike<U[]>;
96
97
  };
97
98
 
@@ -108,363 +109,13 @@ declare function rate<T extends Input>(value: T, condition: string, options?: Ra
108
109
  toMatchInlineSnapshot: (expected?: string) => Promise<void | Output<number> | AsyncExpectError<number>>;
109
110
  toBeGreaterThanOrEqual: (expected: RatingScore) => Promise<Output<number> | AsyncExpectError<number>>;
110
111
  toBeLessThanOrEqual: (expected: RatingScore) => Promise<Output<number> | AsyncExpectError<number>>;
111
- then<TResult1 = Output<number>, TResult2 = never>(onfulfilled?: ((value: Output<number>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): PromiseLike<TResult1 | TResult2>;
112
+ then<TResult1 = Output<number>, TResult2 = never>(onfulfilled?: (value: Output<number>) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
112
113
  value: PromiseLike<number>;
113
114
  };
114
115
 
115
- declare const Models: readonly [{
116
- readonly id: "anthropic__claude-3-haiku-20240307";
117
- readonly name: "Claude 3 Haiku";
118
- readonly integration: "anthropic";
119
- readonly input: {
120
- readonly maxTokens: 200000;
121
- };
122
- readonly output: {
123
- readonly maxTokens: 4096;
124
- };
125
- }, {
126
- readonly id: "anthropic__claude-3-5-sonnet-20240620";
127
- readonly name: "Claude 3.5 Sonnet";
128
- readonly integration: "anthropic";
129
- readonly input: {
130
- readonly maxTokens: 200000;
131
- };
132
- readonly output: {
133
- readonly maxTokens: 4096;
134
- };
135
- }, {
136
- readonly id: "cerebras__llama3.1-70b";
137
- readonly name: "Llama 3.1 70B";
138
- readonly integration: "cerebras";
139
- readonly input: {
140
- readonly maxTokens: 8192;
141
- };
142
- readonly output: {
143
- readonly maxTokens: 8192;
144
- };
145
- }, {
146
- readonly id: "cerebras__llama3.1-8b";
147
- readonly name: "Llama 3.1 8B";
148
- readonly integration: "cerebras";
149
- readonly input: {
150
- readonly maxTokens: 8192;
151
- };
152
- readonly output: {
153
- readonly maxTokens: 8192;
154
- };
155
- }, {
156
- readonly id: "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct";
157
- readonly name: "DeepSeek Coder V2 Instruct";
158
- readonly integration: "fireworks-ai";
159
- readonly input: {
160
- readonly maxTokens: 131072;
161
- };
162
- readonly output: {
163
- readonly maxTokens: 131072;
164
- };
165
- }, {
166
- readonly id: "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct";
167
- readonly name: "DeepSeek Coder V2 Lite";
168
- readonly integration: "fireworks-ai";
169
- readonly input: {
170
- readonly maxTokens: 163840;
171
- };
172
- readonly output: {
173
- readonly maxTokens: 163840;
174
- };
175
- }, {
176
- readonly id: "fireworks-ai__accounts/fireworks/models/firellava-13b";
177
- readonly name: "FireLLaVA-13B";
178
- readonly integration: "fireworks-ai";
179
- readonly input: {
180
- readonly maxTokens: 4096;
181
- };
182
- readonly output: {
183
- readonly maxTokens: 4096;
184
- };
185
- }, {
186
- readonly id: "fireworks-ai__accounts/fireworks/models/firefunction-v2";
187
- readonly name: "Firefunction V2";
188
- readonly integration: "fireworks-ai";
189
- readonly input: {
190
- readonly maxTokens: 8192;
191
- };
192
- readonly output: {
193
- readonly maxTokens: 8192;
194
- };
195
- }, {
196
- readonly id: "fireworks-ai__accounts/fireworks/models/gemma2-9b-it";
197
- readonly name: "Gemma 2 9B Instruct";
198
- readonly integration: "fireworks-ai";
199
- readonly input: {
200
- readonly maxTokens: 8192;
201
- };
202
- readonly output: {
203
- readonly maxTokens: 8192;
204
- };
205
- }, {
206
- readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct";
207
- readonly name: "Llama 3.1 405B Instruct";
208
- readonly integration: "fireworks-ai";
209
- readonly input: {
210
- readonly maxTokens: 131072;
211
- };
212
- readonly output: {
213
- readonly maxTokens: 131072;
214
- };
215
- }, {
216
- readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct";
217
- readonly name: "Llama 3.1 70B Instruct";
218
- readonly integration: "fireworks-ai";
219
- readonly input: {
220
- readonly maxTokens: 131072;
221
- };
222
- readonly output: {
223
- readonly maxTokens: 131072;
224
- };
225
- }, {
226
- readonly id: "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct";
227
- readonly name: "Llama 3.1 8B Instruct";
228
- readonly integration: "fireworks-ai";
229
- readonly input: {
230
- readonly maxTokens: 131072;
231
- };
232
- readonly output: {
233
- readonly maxTokens: 131072;
234
- };
235
- }, {
236
- readonly id: "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct";
237
- readonly name: "Mixtral MoE 8x22B Instruct";
238
- readonly integration: "fireworks-ai";
239
- readonly input: {
240
- readonly maxTokens: 65536;
241
- };
242
- readonly output: {
243
- readonly maxTokens: 65536;
244
- };
245
- }, {
246
- readonly id: "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct";
247
- readonly name: "Mixtral MoE 8x7B Instruct";
248
- readonly integration: "fireworks-ai";
249
- readonly input: {
250
- readonly maxTokens: 32768;
251
- };
252
- readonly output: {
253
- readonly maxTokens: 32768;
254
- };
255
- }, {
256
- readonly id: "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b";
257
- readonly name: "MythoMax L2 13b";
258
- readonly integration: "fireworks-ai";
259
- readonly input: {
260
- readonly maxTokens: 4096;
261
- };
262
- readonly output: {
263
- readonly maxTokens: 4096;
264
- };
265
- }, {
266
- readonly id: "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct";
267
- readonly name: "Qwen2 72b Instruct";
268
- readonly integration: "fireworks-ai";
269
- readonly input: {
270
- readonly maxTokens: 32768;
271
- };
272
- readonly output: {
273
- readonly maxTokens: 32768;
274
- };
275
- }, {
276
- readonly id: "groq__gemma2-9b-it";
277
- readonly name: "Gemma2 9B";
278
- readonly integration: "groq";
279
- readonly input: {
280
- readonly maxTokens: 8192;
281
- };
282
- readonly output: {
283
- readonly maxTokens: 8192;
284
- };
285
- }, {
286
- readonly id: "groq__llama3-70b-8192";
287
- readonly name: "LLaMA 3 70B";
288
- readonly integration: "groq";
289
- readonly input: {
290
- readonly maxTokens: 8192;
291
- };
292
- readonly output: {
293
- readonly maxTokens: 8192;
294
- };
295
- }, {
296
- readonly id: "groq__llama3-8b-8192";
297
- readonly name: "LLaMA 3 8B";
298
- readonly integration: "groq";
299
- readonly input: {
300
- readonly maxTokens: 8192;
301
- };
302
- readonly output: {
303
- readonly maxTokens: 8192;
304
- };
305
- }, {
306
- readonly id: "groq__llama-3.1-70b-versatile";
307
- readonly name: "LLaMA 3.1 70B";
308
- readonly integration: "groq";
309
- readonly input: {
310
- readonly maxTokens: 128000;
311
- };
312
- readonly output: {
313
- readonly maxTokens: 8192;
314
- };
315
- }, {
316
- readonly id: "groq__llama-3.1-8b-instant";
317
- readonly name: "LLaMA 3.1 8B";
318
- readonly integration: "groq";
319
- readonly input: {
320
- readonly maxTokens: 128000;
321
- };
322
- readonly output: {
323
- readonly maxTokens: 8192;
324
- };
325
- }, {
326
- readonly id: "groq__llama-3.2-11b-vision-preview";
327
- readonly name: "LLaMA 3.2 11B Vision";
328
- readonly integration: "groq";
329
- readonly input: {
330
- readonly maxTokens: 128000;
331
- };
332
- readonly output: {
333
- readonly maxTokens: 8192;
334
- };
335
- }, {
336
- readonly id: "groq__llama-3.2-1b-preview";
337
- readonly name: "LLaMA 3.2 1B";
338
- readonly integration: "groq";
339
- readonly input: {
340
- readonly maxTokens: 128000;
341
- };
342
- readonly output: {
343
- readonly maxTokens: 8192;
344
- };
345
- }, {
346
- readonly id: "groq__llama-3.2-3b-preview";
347
- readonly name: "LLaMA 3.2 3B";
348
- readonly integration: "groq";
349
- readonly input: {
350
- readonly maxTokens: 128000;
351
- };
352
- readonly output: {
353
- readonly maxTokens: 8192;
354
- };
355
- }, {
356
- readonly id: "groq__llama-3.2-90b-vision-preview";
357
- readonly name: "LLaMA 3.2 90B Vision";
358
- readonly integration: "groq";
359
- readonly input: {
360
- readonly maxTokens: 128000;
361
- };
362
- readonly output: {
363
- readonly maxTokens: 8192;
364
- };
365
- }, {
366
- readonly id: "groq__llama-3.3-70b-versatile";
367
- readonly name: "LLaMA 3.3 70B";
368
- readonly integration: "groq";
369
- readonly input: {
370
- readonly maxTokens: 128000;
371
- };
372
- readonly output: {
373
- readonly maxTokens: 32768;
374
- };
375
- }, {
376
- readonly id: "groq__mixtral-8x7b-32768";
377
- readonly name: "Mixtral 8x7B";
378
- readonly integration: "groq";
379
- readonly input: {
380
- readonly maxTokens: 32768;
381
- };
382
- readonly output: {
383
- readonly maxTokens: 32768;
384
- };
385
- }, {
386
- readonly id: "openai__o1-2024-12-17";
387
- readonly name: "GPT o1";
388
- readonly integration: "openai";
389
- readonly input: {
390
- readonly maxTokens: 200000;
391
- };
392
- readonly output: {
393
- readonly maxTokens: 100000;
394
- };
395
- }, {
396
- readonly id: "openai__o1-mini-2024-09-12";
397
- readonly name: "GPT o1-mini";
398
- readonly integration: "openai";
399
- readonly input: {
400
- readonly maxTokens: 128000;
401
- };
402
- readonly output: {
403
- readonly maxTokens: 65536;
404
- };
405
- }, {
406
- readonly id: "openai__gpt-3.5-turbo-0125";
407
- readonly name: "GPT-3.5 Turbo";
408
- readonly integration: "openai";
409
- readonly input: {
410
- readonly maxTokens: 128000;
411
- };
412
- readonly output: {
413
- readonly maxTokens: 4096;
414
- };
415
- }, {
416
- readonly id: "openai__gpt-4-turbo-2024-04-09";
417
- readonly name: "GPT-4 Turbo";
418
- readonly integration: "openai";
419
- readonly input: {
420
- readonly maxTokens: 128000;
421
- };
422
- readonly output: {
423
- readonly maxTokens: 4096;
424
- };
425
- }, {
426
- readonly id: "openai__gpt-4o-2024-08-06";
427
- readonly name: "GPT-4o (August 2024)";
428
- readonly integration: "openai";
429
- readonly input: {
430
- readonly maxTokens: 128000;
431
- };
432
- readonly output: {
433
- readonly maxTokens: 16384;
434
- };
435
- }, {
436
- readonly id: "openai__gpt-4o-2024-05-13";
437
- readonly name: "GPT-4o (May 2024)";
438
- readonly integration: "openai";
439
- readonly input: {
440
- readonly maxTokens: 128000;
441
- };
442
- readonly output: {
443
- readonly maxTokens: 4096;
444
- };
445
- }, {
446
- readonly id: "openai__gpt-4o-2024-11-20";
447
- readonly name: "GPT-4o (November 2024)";
448
- readonly integration: "openai";
449
- readonly input: {
450
- readonly maxTokens: 128000;
451
- };
452
- readonly output: {
453
- readonly maxTokens: 16384;
454
- };
455
- }, {
456
- readonly id: "openai__gpt-4o-mini-2024-07-18";
457
- readonly name: "GPT-4o Mini";
458
- readonly integration: "openai";
459
- readonly input: {
460
- readonly maxTokens: 128000;
461
- };
462
- readonly output: {
463
- readonly maxTokens: 16384;
464
- };
465
- }];
116
+ type Model = llm.Model;
466
117
 
467
- type EvaluatorModel = (typeof Models)[number]['id'];
118
+ type EvaluatorModel = Model['id'];
468
119
 
469
120
  declare const setEvaluator: (model: EvaluatorModel) => void;
470
121
 
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  export { compare } from "./task/compare";
3
2
  export { check } from "./assertions/check";
4
3
  export { extract } from "./assertions/extract";
package/dist/llm.js ADDED
File without changes
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { z } from "@bpinternal/zui";
3
2
  import { createTaskCollector, getCurrentSuite } from "vitest/suite";
4
3
  import { Deferred } from "../utils/deferred";
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { expect } from "vitest";
3
2
  import { getCurrentTest } from "vitest/suite";
4
3
  import { Context } from "../context";
@@ -1,5 +1,7 @@
1
- "use strict";
2
1
  export class Deferred {
2
+ promise;
3
+ _resolve;
4
+ _reject;
3
5
  constructor() {
4
6
  this.promise = new Promise((resolve, reject) => {
5
7
  this._resolve = resolve;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  import { z } from "@bpinternal/zui";
3
2
  import JSON5 from "json5";
4
3
  import { Context } from "../context";
@@ -21,7 +20,6 @@ const Options = z.object({
21
20
  systemMessage: z.string(),
22
21
  examples: z.array(Example).default([]),
23
22
  input: Input,
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
23
  outputSchema: z.custom((value) => typeof value === "object" && value !== null && "_def" in value),
26
24
  model: z.string()
27
25
  });
@@ -48,7 +46,7 @@ ${options.systemMessage}
48
46
  ---
49
47
  Please generate a JSON response with the following format:
50
48
  \`\`\`typescript
51
- ${await outputSchema.toTypescriptAsync()}
49
+ ${outputSchema.toTypescriptType()}
52
50
  \`\`\`
53
51
  `.trim(),
54
52
  messages: [
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@botpress/vai",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Vitest AI (vai) – a vitest extension for testing with LLMs",
5
+ "types": "./dist/index.d.ts",
5
6
  "exports": {
6
7
  ".": {
7
8
  "types": "./dist/index.d.ts",
@@ -10,37 +11,39 @@
10
11
  }
11
12
  },
12
13
  "scripts": {
13
- "build": "npm run build:types && npm run build:neutral",
14
- "build:neutral": "esbuild src/**/*.ts src/*.ts --platform=neutral --outdir=dist",
14
+ "check:type": "tsc --noEmit",
15
+ "build": "pnpm run build:types && pnpm run build:neutral",
16
+ "build:neutral": "ts-node -T ./build.ts",
15
17
  "build:types": "tsup",
16
18
  "watch": "tsup --watch",
17
- "test": "vitest run --config vitest.config.ts",
18
- "test:update": "vitest -u run --config vitest.config.ts",
19
- "test:watch": "vitest --config vitest.config.ts",
20
- "build-with-latest-models": "pnpm run update-types && pnpm run update-models && pnpm run build",
21
- "update-models": "ts-node ./src/scripts/update-models.ts",
22
- "update-types": "ts-node ./src/scripts/update-types.ts"
19
+ "test:e2e": "vitest run --config vitest.config.ts",
20
+ "test:e2e:update": "vitest -u run --config vitest.config.ts",
21
+ "test:e2e:watch": "vitest --config vitest.config.ts"
23
22
  },
24
23
  "keywords": [],
25
24
  "author": "",
26
25
  "license": "ISC",
27
26
  "dependencies": {
28
- "json5": "^2.2.1",
29
- "jsonrepair": "^3.2.0"
27
+ "json5": "^2.2.3",
28
+ "jsonrepair": "^3.10.0"
30
29
  },
31
30
  "devDependencies": {
32
- "@types/lodash": "^4.17.0",
33
- "dotenv": "^16.3.1",
34
- "esbuild": "^0.24.2",
35
- "ts-node": "^10.9.2",
36
- "tsup": "^8.3.5",
37
- "typescript": "^5.7.2"
31
+ "@botpress/common": "workspace:*",
32
+ "@types/lodash": "^4.14.191",
33
+ "dotenv": "^16.4.4",
34
+ "esbuild": "^0.16.12",
35
+ "glob": "^9.3.4",
36
+ "tsup": "^8.0.2"
38
37
  },
39
38
  "peerDependencies": {
40
- "@botpress/client": "^0.40.0",
41
- "@botpress/wasm": "^1.0.1",
42
- "@bpinternal/zui": "^0.13.4",
39
+ "@botpress/client": "1.15.1",
40
+ "@bpinternal/thicktoken": "^1.0.1",
41
+ "@bpinternal/zui": "^1.0.0",
43
42
  "lodash": "^4.17.21",
44
43
  "vitest": "^2 || ^3 || ^4 || ^5"
45
- }
44
+ },
45
+ "engines": {
46
+ "node": ">=18.0.0"
47
+ },
48
+ "packageManager": "pnpm@8.6.2"
46
49
  }
package/tsconfig.json CHANGED
@@ -1,28 +1,8 @@
1
1
  {
2
+ "extends": "../../tsconfig.json",
2
3
  "compilerOptions": {
3
- "esModuleInterop": true,
4
- "module": "ESNext",
5
- "moduleResolution": "Node",
6
- "target": "ES2017",
7
- "strict": true,
8
- "jsx": "preserve",
9
- "noUnusedLocals": true,
10
- "noUnusedParameters": true,
11
- "noUncheckedIndexedAccess": true,
12
- "allowSyntheticDefaultImports": true,
13
- "lib": ["dom", "ESNext", "dom.iterable"],
14
- "allowJs": false,
15
- "declaration": false,
16
- "skipLibCheck": true,
17
- "forceConsistentCasingInFileNames": true,
18
- "noEmit": false,
19
- "resolveJsonModule": true,
20
- "isolatedModules": true
4
+ "strict": false
21
5
  },
22
6
  "exclude": ["node_modules", "dist"],
23
- "include": ["src/**/*", "vitest.d.ts"],
24
- "ts-node": {
25
- "esm": true,
26
- "require": ["dotenv/config", "./ensure-env.cjs"]
27
- }
7
+ "include": ["src/**/*", "vitest.d.ts", "e2e/**/*"]
28
8
  }
package/tsup.config.ts CHANGED
@@ -6,5 +6,5 @@ export default defineConfig({
6
6
  outDir: 'dist',
7
7
  platform: 'neutral',
8
8
  clean: true,
9
- bundle: false
9
+ bundle: false,
10
10
  })
package/vitest.config.ts CHANGED
@@ -3,7 +3,9 @@ import { defineConfig } from 'vitest/config'
3
3
 
4
4
  export default defineConfig({
5
5
  test: {
6
- include: ['./src/**/*.test.ts'],
7
- setupFiles: './vitest.setup.ts'
8
- }
6
+ retry: 2, // because LLMs can fail
7
+ testTimeout: 60_000, // because LLMs can be slow
8
+ include: ['./e2e/**/*.test.ts'],
9
+ setupFiles: './vitest.setup.ts',
10
+ },
9
11
  })
package/vitest.setup.ts CHANGED
@@ -1,13 +1,39 @@
1
+ import { Client } from '@botpress/client'
1
2
  import { beforeAll } from 'vitest'
2
3
  import { setupClient } from './src/hooks/setupClient'
3
- import { Client } from '@botpress/client'
4
4
 
5
5
  beforeAll(async () => {
6
- setupClient(
7
- new Client({
8
- apiUrl: process.env.CLOUD_API_ENDPOINT ?? 'https://api.botpress.dev',
9
- botId: process.env.CLOUD_BOT_ID,
10
- token: process.env.CLOUD_PAT
11
- })
12
- )
6
+ if (!process.env.CLOUD_PAT) {
7
+ throw new Error('Missing CLOUD_PAT')
8
+ }
9
+
10
+ if (!process.env.CLOUD_BOT_ID) {
11
+ throw new Error('Missing CLOUD_BOT_ID')
12
+ }
13
+
14
+ const apiUrl: string = process.env.CLOUD_API_ENDPOINT ?? 'https://api.botpress.dev'
15
+ const botId: string = process.env.CLOUD_BOT_ID
16
+ const token: string = process.env.CLOUD_PAT
17
+
18
+ const client = new Client({
19
+ apiUrl,
20
+ botId,
21
+ token,
22
+ })
23
+
24
+ const { integration } = await client.getPublicIntegration({
25
+ name: 'openai',
26
+ version: 'latest',
27
+ })
28
+
29
+ await client.updateBot({
30
+ id: botId,
31
+ integrations: {
32
+ [integration.id]: {
33
+ enabled: true,
34
+ },
35
+ },
36
+ })
37
+
38
+ setupClient(client)
13
39
  })
package/dist/models.js DELETED
@@ -1,388 +0,0 @@
1
- "use strict";
2
- export const Models = [
3
- {
4
- "id": "anthropic__claude-3-haiku-20240307",
5
- "name": "Claude 3 Haiku",
6
- "integration": "anthropic",
7
- "input": {
8
- "maxTokens": 2e5
9
- },
10
- "output": {
11
- "maxTokens": 4096
12
- }
13
- },
14
- {
15
- "id": "anthropic__claude-3-5-sonnet-20240620",
16
- "name": "Claude 3.5 Sonnet",
17
- "integration": "anthropic",
18
- "input": {
19
- "maxTokens": 2e5
20
- },
21
- "output": {
22
- "maxTokens": 4096
23
- }
24
- },
25
- {
26
- "id": "cerebras__llama3.1-70b",
27
- "name": "Llama 3.1 70B",
28
- "integration": "cerebras",
29
- "input": {
30
- "maxTokens": 8192
31
- },
32
- "output": {
33
- "maxTokens": 8192
34
- }
35
- },
36
- {
37
- "id": "cerebras__llama3.1-8b",
38
- "name": "Llama 3.1 8B",
39
- "integration": "cerebras",
40
- "input": {
41
- "maxTokens": 8192
42
- },
43
- "output": {
44
- "maxTokens": 8192
45
- }
46
- },
47
- {
48
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct",
49
- "name": "DeepSeek Coder V2 Instruct",
50
- "integration": "fireworks-ai",
51
- "input": {
52
- "maxTokens": 131072
53
- },
54
- "output": {
55
- "maxTokens": 131072
56
- }
57
- },
58
- {
59
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct",
60
- "name": "DeepSeek Coder V2 Lite",
61
- "integration": "fireworks-ai",
62
- "input": {
63
- "maxTokens": 163840
64
- },
65
- "output": {
66
- "maxTokens": 163840
67
- }
68
- },
69
- {
70
- "id": "fireworks-ai__accounts/fireworks/models/firellava-13b",
71
- "name": "FireLLaVA-13B",
72
- "integration": "fireworks-ai",
73
- "input": {
74
- "maxTokens": 4096
75
- },
76
- "output": {
77
- "maxTokens": 4096
78
- }
79
- },
80
- {
81
- "id": "fireworks-ai__accounts/fireworks/models/firefunction-v2",
82
- "name": "Firefunction V2",
83
- "integration": "fireworks-ai",
84
- "input": {
85
- "maxTokens": 8192
86
- },
87
- "output": {
88
- "maxTokens": 8192
89
- }
90
- },
91
- {
92
- "id": "fireworks-ai__accounts/fireworks/models/gemma2-9b-it",
93
- "name": "Gemma 2 9B Instruct",
94
- "integration": "fireworks-ai",
95
- "input": {
96
- "maxTokens": 8192
97
- },
98
- "output": {
99
- "maxTokens": 8192
100
- }
101
- },
102
- {
103
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct",
104
- "name": "Llama 3.1 405B Instruct",
105
- "integration": "fireworks-ai",
106
- "input": {
107
- "maxTokens": 131072
108
- },
109
- "output": {
110
- "maxTokens": 131072
111
- }
112
- },
113
- {
114
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct",
115
- "name": "Llama 3.1 70B Instruct",
116
- "integration": "fireworks-ai",
117
- "input": {
118
- "maxTokens": 131072
119
- },
120
- "output": {
121
- "maxTokens": 131072
122
- }
123
- },
124
- {
125
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct",
126
- "name": "Llama 3.1 8B Instruct",
127
- "integration": "fireworks-ai",
128
- "input": {
129
- "maxTokens": 131072
130
- },
131
- "output": {
132
- "maxTokens": 131072
133
- }
134
- },
135
- {
136
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct",
137
- "name": "Mixtral MoE 8x22B Instruct",
138
- "integration": "fireworks-ai",
139
- "input": {
140
- "maxTokens": 65536
141
- },
142
- "output": {
143
- "maxTokens": 65536
144
- }
145
- },
146
- {
147
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct",
148
- "name": "Mixtral MoE 8x7B Instruct",
149
- "integration": "fireworks-ai",
150
- "input": {
151
- "maxTokens": 32768
152
- },
153
- "output": {
154
- "maxTokens": 32768
155
- }
156
- },
157
- {
158
- "id": "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b",
159
- "name": "MythoMax L2 13b",
160
- "integration": "fireworks-ai",
161
- "input": {
162
- "maxTokens": 4096
163
- },
164
- "output": {
165
- "maxTokens": 4096
166
- }
167
- },
168
- {
169
- "id": "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct",
170
- "name": "Qwen2 72b Instruct",
171
- "integration": "fireworks-ai",
172
- "input": {
173
- "maxTokens": 32768
174
- },
175
- "output": {
176
- "maxTokens": 32768
177
- }
178
- },
179
- {
180
- "id": "groq__gemma2-9b-it",
181
- "name": "Gemma2 9B",
182
- "integration": "groq",
183
- "input": {
184
- "maxTokens": 8192
185
- },
186
- "output": {
187
- "maxTokens": 8192
188
- }
189
- },
190
- {
191
- "id": "groq__llama3-70b-8192",
192
- "name": "LLaMA 3 70B",
193
- "integration": "groq",
194
- "input": {
195
- "maxTokens": 8192
196
- },
197
- "output": {
198
- "maxTokens": 8192
199
- }
200
- },
201
- {
202
- "id": "groq__llama3-8b-8192",
203
- "name": "LLaMA 3 8B",
204
- "integration": "groq",
205
- "input": {
206
- "maxTokens": 8192
207
- },
208
- "output": {
209
- "maxTokens": 8192
210
- }
211
- },
212
- {
213
- "id": "groq__llama-3.1-70b-versatile",
214
- "name": "LLaMA 3.1 70B",
215
- "integration": "groq",
216
- "input": {
217
- "maxTokens": 128e3
218
- },
219
- "output": {
220
- "maxTokens": 8192
221
- }
222
- },
223
- {
224
- "id": "groq__llama-3.1-8b-instant",
225
- "name": "LLaMA 3.1 8B",
226
- "integration": "groq",
227
- "input": {
228
- "maxTokens": 128e3
229
- },
230
- "output": {
231
- "maxTokens": 8192
232
- }
233
- },
234
- {
235
- "id": "groq__llama-3.2-11b-vision-preview",
236
- "name": "LLaMA 3.2 11B Vision",
237
- "integration": "groq",
238
- "input": {
239
- "maxTokens": 128e3
240
- },
241
- "output": {
242
- "maxTokens": 8192
243
- }
244
- },
245
- {
246
- "id": "groq__llama-3.2-1b-preview",
247
- "name": "LLaMA 3.2 1B",
248
- "integration": "groq",
249
- "input": {
250
- "maxTokens": 128e3
251
- },
252
- "output": {
253
- "maxTokens": 8192
254
- }
255
- },
256
- {
257
- "id": "groq__llama-3.2-3b-preview",
258
- "name": "LLaMA 3.2 3B",
259
- "integration": "groq",
260
- "input": {
261
- "maxTokens": 128e3
262
- },
263
- "output": {
264
- "maxTokens": 8192
265
- }
266
- },
267
- {
268
- "id": "groq__llama-3.2-90b-vision-preview",
269
- "name": "LLaMA 3.2 90B Vision",
270
- "integration": "groq",
271
- "input": {
272
- "maxTokens": 128e3
273
- },
274
- "output": {
275
- "maxTokens": 8192
276
- }
277
- },
278
- {
279
- "id": "groq__llama-3.3-70b-versatile",
280
- "name": "LLaMA 3.3 70B",
281
- "integration": "groq",
282
- "input": {
283
- "maxTokens": 128e3
284
- },
285
- "output": {
286
- "maxTokens": 32768
287
- }
288
- },
289
- {
290
- "id": "groq__mixtral-8x7b-32768",
291
- "name": "Mixtral 8x7B",
292
- "integration": "groq",
293
- "input": {
294
- "maxTokens": 32768
295
- },
296
- "output": {
297
- "maxTokens": 32768
298
- }
299
- },
300
- {
301
- "id": "openai__o1-2024-12-17",
302
- "name": "GPT o1",
303
- "integration": "openai",
304
- "input": {
305
- "maxTokens": 2e5
306
- },
307
- "output": {
308
- "maxTokens": 1e5
309
- }
310
- },
311
- {
312
- "id": "openai__o1-mini-2024-09-12",
313
- "name": "GPT o1-mini",
314
- "integration": "openai",
315
- "input": {
316
- "maxTokens": 128e3
317
- },
318
- "output": {
319
- "maxTokens": 65536
320
- }
321
- },
322
- {
323
- "id": "openai__gpt-3.5-turbo-0125",
324
- "name": "GPT-3.5 Turbo",
325
- "integration": "openai",
326
- "input": {
327
- "maxTokens": 128e3
328
- },
329
- "output": {
330
- "maxTokens": 4096
331
- }
332
- },
333
- {
334
- "id": "openai__gpt-4-turbo-2024-04-09",
335
- "name": "GPT-4 Turbo",
336
- "integration": "openai",
337
- "input": {
338
- "maxTokens": 128e3
339
- },
340
- "output": {
341
- "maxTokens": 4096
342
- }
343
- },
344
- {
345
- "id": "openai__gpt-4o-2024-08-06",
346
- "name": "GPT-4o (August 2024)",
347
- "integration": "openai",
348
- "input": {
349
- "maxTokens": 128e3
350
- },
351
- "output": {
352
- "maxTokens": 16384
353
- }
354
- },
355
- {
356
- "id": "openai__gpt-4o-2024-05-13",
357
- "name": "GPT-4o (May 2024)",
358
- "integration": "openai",
359
- "input": {
360
- "maxTokens": 128e3
361
- },
362
- "output": {
363
- "maxTokens": 4096
364
- }
365
- },
366
- {
367
- "id": "openai__gpt-4o-2024-11-20",
368
- "name": "GPT-4o (November 2024)",
369
- "integration": "openai",
370
- "input": {
371
- "maxTokens": 128e3
372
- },
373
- "output": {
374
- "maxTokens": 16384
375
- }
376
- },
377
- {
378
- "id": "openai__gpt-4o-mini-2024-07-18",
379
- "name": "GPT-4o Mini",
380
- "integration": "openai",
381
- "input": {
382
- "maxTokens": 128e3
383
- },
384
- "output": {
385
- "maxTokens": 16384
386
- }
387
- }
388
- ];
@@ -1,58 +0,0 @@
1
- "use strict";
2
- import { Client } from "@botpress/client";
3
- import _ from "lodash";
4
- import fs from "node:fs";
5
- const LLM_LIST_MODELS = "listLanguageModels";
6
- const client = new Client({
7
- apiUrl: process.env.CLOUD_API_ENDPOINT,
8
- botId: process.env.CLOUD_BOT_ID,
9
- token: process.env.CLOUD_PAT
10
- });
11
- const { bot } = await client.getBot({
12
- id: process.env.CLOUD_BOT_ID
13
- });
14
- const models = [];
15
- for (const integrationId in bot.integrations) {
16
- const botIntegration = bot.integrations[integrationId];
17
- if (botIntegration?.public && botIntegration?.enabled && botIntegration?.status === "registered") {
18
- try {
19
- const { integration } = await client.getPublicIntegrationById({
20
- id: botIntegration.id
21
- });
22
- const canListModels = Object.keys(integration.actions).includes(LLM_LIST_MODELS);
23
- if (!canListModels) {
24
- continue;
25
- }
26
- const { output } = await client.callAction({
27
- type: `${integration.name}:${LLM_LIST_MODELS}`,
28
- input: {}
29
- });
30
- if (_.isArray(output?.models)) {
31
- for (const model of output.models) {
32
- models.push({
33
- id: `${integration.name}__${model.id}`,
34
- name: model.name,
35
- integration: integration.name,
36
- input: { maxTokens: model.input.maxTokens },
37
- output: { maxTokens: model.output.maxTokens }
38
- });
39
- }
40
- }
41
- } catch (err) {
42
- console.error("Error fetching integration:", err instanceof Error ? err.message : `${err}`);
43
- }
44
- }
45
- }
46
- const content = JSON.stringify(_.orderBy(models, ["integration", "name"]), null, 2);
47
- fs.writeFileSync(
48
- "./src/models.ts",
49
- `
50
- // This file is generated. Do not edit it manually.
51
- // See 'scripts/update-models.ts'
52
-
53
- /* eslint-disable */
54
- /* tslint:disable */
55
-
56
- export const Models = ${content} as const`,
57
- "utf-8"
58
- );
@@ -1,42 +0,0 @@
1
- "use strict";
2
- import { Client } from "@botpress/client";
3
- import { z } from "@bpinternal/zui";
4
- import _ from "lodash";
5
- import fs from "node:fs";
6
- import path from "node:path";
7
- const Interfaces = ["llm"];
8
- const client = new Client({
9
- apiUrl: process.env.CLOUD_API_ENDPOINT,
10
- botId: process.env.CLOUD_BOT_ID,
11
- token: process.env.CLOUD_PAT
12
- });
13
- for (const name of Interfaces) {
14
- const { interfaces } = await client.listInterfaces({
15
- name
16
- });
17
- const { interface: latest } = await client.getInterface({
18
- id: _.maxBy(interfaces, "version").id
19
- });
20
- for (const action of Object.keys(latest.actions)) {
21
- const references = Object.keys(latest.entities).reduce((acc, key) => {
22
- return { ...acc, [key]: z.fromJsonSchema(latest.entities?.[key]?.schema) };
23
- }, {});
24
- const input = latest.actions[action]?.input.schema;
25
- const output = latest.actions[action]?.output.schema;
26
- const types = `
27
- // This file is generated. Do not edit it manually.
28
- // See 'scripts/update-models.ts'
29
-
30
- /* eslint-disable */
31
- /* tslint:disable */
32
-
33
- export namespace ${name} {
34
- export namespace ${action} {
35
- export ${z.fromJsonSchema(input).title("Input").dereference(references).toTypescript({ declaration: "type" })};
36
- export ${z.fromJsonSchema(output).title("Output").dereference(references).toTypescript({ declaration: "type" })};
37
- }
38
- }`;
39
- fs.mkdirSync(path.resolve(`./src/sdk-interfaces/${name}`), { recursive: true });
40
- fs.writeFileSync(path.resolve(`./src/sdk-interfaces/${name}/${action}.ts`), types);
41
- }
42
- }