@botpress/vai 0.0.5 → 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
+ })
@@ -15,6 +15,7 @@ export function check(value, condition, options) {
15
15
  input: value
16
16
  });
17
17
  return {
18
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
18
19
  ...toAssertion(promise),
19
20
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
20
21
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)
@@ -20,7 +20,7 @@ ${stack}
20
20
  });
21
21
  try {
22
22
  expect((await promise).result).toMatchObject(obj);
23
- } catch (err) {
23
+ } catch {
24
24
  const newError = new Error();
25
25
  newError.stack = newStack;
26
26
  expect.getState().snapshotState.match({
@@ -18,6 +18,7 @@ ${options.description}
18
18
  input: value
19
19
  });
20
20
  return {
21
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
21
22
  ...toAssertion(promise),
22
23
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
23
24
  toMatchObject: (expected) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),
@@ -53,6 +53,7 @@ You need to return an array of objects with the index and a boolean value indica
53
53
  };
54
54
  });
55
55
  return {
56
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
56
57
  ...toAssertion(promise),
57
58
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
58
59
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
@@ -23,6 +23,7 @@ Criteria: ${condition}`,
23
23
  };
24
24
  });
25
25
  return {
26
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
26
27
  ...toAssertion(promise),
27
28
  toBe: (expected) => asyncExpect(promise, (expect) => expect.toEqual(expected)),
28
29
  toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),
package/dist/index.d.ts CHANGED
@@ -1,35 +1,36 @@
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
+ }, "strip", {
33
34
  reason?: string;
34
35
  result?: any;
35
36
  }, {
@@ -112,359 +113,9 @@ declare function rate<T extends Input>(value: T, condition: string, options?: Ra
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/llm.js ADDED
File without changes
@@ -1,4 +1,7 @@
1
1
  export class Deferred {
2
+ promise;
3
+ _resolve;
4
+ _reject;
2
5
  constructor() {
3
6
  this.promise = new Promise((resolve, reject) => {
4
7
  this._resolve = resolve;
@@ -20,7 +20,6 @@ const Options = z.object({
20
20
  systemMessage: z.string(),
21
21
  examples: z.array(Example).default([]),
22
22
  input: Input,
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
23
  outputSchema: z.custom((value) => typeof value === "object" && value !== null && "_def" in value),
25
24
  model: z.string()
26
25
  });
@@ -47,7 +46,7 @@ ${options.systemMessage}
47
46
  ---
48
47
  Please generate a JSON response with the following format:
49
48
  \`\`\`typescript
50
- ${await outputSchema.toTypescriptAsync()}
49
+ ${outputSchema.toTypescriptType()}
51
50
  \`\`\`
52
51
  `.trim(),
53
52
  messages: [
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@botpress/vai",
3
- "version": "0.0.5",
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": false,
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
@@ -5,7 +5,7 @@ export default defineConfig({
5
5
  test: {
6
6
  retry: 2, // because LLMs can fail
7
7
  testTimeout: 60_000, // because LLMs can be slow
8
- include: ['./src/**/*.test.ts'],
9
- setupFiles: './vitest.setup.ts'
10
- }
8
+ include: ['./e2e/**/*.test.ts'],
9
+ setupFiles: './vitest.setup.ts',
10
+ },
11
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,387 +0,0 @@
1
- export const Models = [
2
- {
3
- "id": "anthropic__claude-3-haiku-20240307",
4
- "name": "Claude 3 Haiku",
5
- "integration": "anthropic",
6
- "input": {
7
- "maxTokens": 2e5
8
- },
9
- "output": {
10
- "maxTokens": 4096
11
- }
12
- },
13
- {
14
- "id": "anthropic__claude-3-5-sonnet-20240620",
15
- "name": "Claude 3.5 Sonnet",
16
- "integration": "anthropic",
17
- "input": {
18
- "maxTokens": 2e5
19
- },
20
- "output": {
21
- "maxTokens": 4096
22
- }
23
- },
24
- {
25
- "id": "cerebras__llama3.1-70b",
26
- "name": "Llama 3.1 70B",
27
- "integration": "cerebras",
28
- "input": {
29
- "maxTokens": 8192
30
- },
31
- "output": {
32
- "maxTokens": 8192
33
- }
34
- },
35
- {
36
- "id": "cerebras__llama3.1-8b",
37
- "name": "Llama 3.1 8B",
38
- "integration": "cerebras",
39
- "input": {
40
- "maxTokens": 8192
41
- },
42
- "output": {
43
- "maxTokens": 8192
44
- }
45
- },
46
- {
47
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-instruct",
48
- "name": "DeepSeek Coder V2 Instruct",
49
- "integration": "fireworks-ai",
50
- "input": {
51
- "maxTokens": 131072
52
- },
53
- "output": {
54
- "maxTokens": 131072
55
- }
56
- },
57
- {
58
- "id": "fireworks-ai__accounts/fireworks/models/deepseek-coder-v2-lite-instruct",
59
- "name": "DeepSeek Coder V2 Lite",
60
- "integration": "fireworks-ai",
61
- "input": {
62
- "maxTokens": 163840
63
- },
64
- "output": {
65
- "maxTokens": 163840
66
- }
67
- },
68
- {
69
- "id": "fireworks-ai__accounts/fireworks/models/firellava-13b",
70
- "name": "FireLLaVA-13B",
71
- "integration": "fireworks-ai",
72
- "input": {
73
- "maxTokens": 4096
74
- },
75
- "output": {
76
- "maxTokens": 4096
77
- }
78
- },
79
- {
80
- "id": "fireworks-ai__accounts/fireworks/models/firefunction-v2",
81
- "name": "Firefunction V2",
82
- "integration": "fireworks-ai",
83
- "input": {
84
- "maxTokens": 8192
85
- },
86
- "output": {
87
- "maxTokens": 8192
88
- }
89
- },
90
- {
91
- "id": "fireworks-ai__accounts/fireworks/models/gemma2-9b-it",
92
- "name": "Gemma 2 9B Instruct",
93
- "integration": "fireworks-ai",
94
- "input": {
95
- "maxTokens": 8192
96
- },
97
- "output": {
98
- "maxTokens": 8192
99
- }
100
- },
101
- {
102
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-405b-instruct",
103
- "name": "Llama 3.1 405B Instruct",
104
- "integration": "fireworks-ai",
105
- "input": {
106
- "maxTokens": 131072
107
- },
108
- "output": {
109
- "maxTokens": 131072
110
- }
111
- },
112
- {
113
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-70b-instruct",
114
- "name": "Llama 3.1 70B Instruct",
115
- "integration": "fireworks-ai",
116
- "input": {
117
- "maxTokens": 131072
118
- },
119
- "output": {
120
- "maxTokens": 131072
121
- }
122
- },
123
- {
124
- "id": "fireworks-ai__accounts/fireworks/models/llama-v3p1-8b-instruct",
125
- "name": "Llama 3.1 8B Instruct",
126
- "integration": "fireworks-ai",
127
- "input": {
128
- "maxTokens": 131072
129
- },
130
- "output": {
131
- "maxTokens": 131072
132
- }
133
- },
134
- {
135
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x22b-instruct",
136
- "name": "Mixtral MoE 8x22B Instruct",
137
- "integration": "fireworks-ai",
138
- "input": {
139
- "maxTokens": 65536
140
- },
141
- "output": {
142
- "maxTokens": 65536
143
- }
144
- },
145
- {
146
- "id": "fireworks-ai__accounts/fireworks/models/mixtral-8x7b-instruct",
147
- "name": "Mixtral MoE 8x7B Instruct",
148
- "integration": "fireworks-ai",
149
- "input": {
150
- "maxTokens": 32768
151
- },
152
- "output": {
153
- "maxTokens": 32768
154
- }
155
- },
156
- {
157
- "id": "fireworks-ai__accounts/fireworks/models/mythomax-l2-13b",
158
- "name": "MythoMax L2 13b",
159
- "integration": "fireworks-ai",
160
- "input": {
161
- "maxTokens": 4096
162
- },
163
- "output": {
164
- "maxTokens": 4096
165
- }
166
- },
167
- {
168
- "id": "fireworks-ai__accounts/fireworks/models/qwen2-72b-instruct",
169
- "name": "Qwen2 72b Instruct",
170
- "integration": "fireworks-ai",
171
- "input": {
172
- "maxTokens": 32768
173
- },
174
- "output": {
175
- "maxTokens": 32768
176
- }
177
- },
178
- {
179
- "id": "groq__gemma2-9b-it",
180
- "name": "Gemma2 9B",
181
- "integration": "groq",
182
- "input": {
183
- "maxTokens": 8192
184
- },
185
- "output": {
186
- "maxTokens": 8192
187
- }
188
- },
189
- {
190
- "id": "groq__llama3-70b-8192",
191
- "name": "LLaMA 3 70B",
192
- "integration": "groq",
193
- "input": {
194
- "maxTokens": 8192
195
- },
196
- "output": {
197
- "maxTokens": 8192
198
- }
199
- },
200
- {
201
- "id": "groq__llama3-8b-8192",
202
- "name": "LLaMA 3 8B",
203
- "integration": "groq",
204
- "input": {
205
- "maxTokens": 8192
206
- },
207
- "output": {
208
- "maxTokens": 8192
209
- }
210
- },
211
- {
212
- "id": "groq__llama-3.1-70b-versatile",
213
- "name": "LLaMA 3.1 70B",
214
- "integration": "groq",
215
- "input": {
216
- "maxTokens": 128e3
217
- },
218
- "output": {
219
- "maxTokens": 8192
220
- }
221
- },
222
- {
223
- "id": "groq__llama-3.1-8b-instant",
224
- "name": "LLaMA 3.1 8B",
225
- "integration": "groq",
226
- "input": {
227
- "maxTokens": 128e3
228
- },
229
- "output": {
230
- "maxTokens": 8192
231
- }
232
- },
233
- {
234
- "id": "groq__llama-3.2-11b-vision-preview",
235
- "name": "LLaMA 3.2 11B Vision",
236
- "integration": "groq",
237
- "input": {
238
- "maxTokens": 128e3
239
- },
240
- "output": {
241
- "maxTokens": 8192
242
- }
243
- },
244
- {
245
- "id": "groq__llama-3.2-1b-preview",
246
- "name": "LLaMA 3.2 1B",
247
- "integration": "groq",
248
- "input": {
249
- "maxTokens": 128e3
250
- },
251
- "output": {
252
- "maxTokens": 8192
253
- }
254
- },
255
- {
256
- "id": "groq__llama-3.2-3b-preview",
257
- "name": "LLaMA 3.2 3B",
258
- "integration": "groq",
259
- "input": {
260
- "maxTokens": 128e3
261
- },
262
- "output": {
263
- "maxTokens": 8192
264
- }
265
- },
266
- {
267
- "id": "groq__llama-3.2-90b-vision-preview",
268
- "name": "LLaMA 3.2 90B Vision",
269
- "integration": "groq",
270
- "input": {
271
- "maxTokens": 128e3
272
- },
273
- "output": {
274
- "maxTokens": 8192
275
- }
276
- },
277
- {
278
- "id": "groq__llama-3.3-70b-versatile",
279
- "name": "LLaMA 3.3 70B",
280
- "integration": "groq",
281
- "input": {
282
- "maxTokens": 128e3
283
- },
284
- "output": {
285
- "maxTokens": 32768
286
- }
287
- },
288
- {
289
- "id": "groq__mixtral-8x7b-32768",
290
- "name": "Mixtral 8x7B",
291
- "integration": "groq",
292
- "input": {
293
- "maxTokens": 32768
294
- },
295
- "output": {
296
- "maxTokens": 32768
297
- }
298
- },
299
- {
300
- "id": "openai__o1-2024-12-17",
301
- "name": "GPT o1",
302
- "integration": "openai",
303
- "input": {
304
- "maxTokens": 2e5
305
- },
306
- "output": {
307
- "maxTokens": 1e5
308
- }
309
- },
310
- {
311
- "id": "openai__o1-mini-2024-09-12",
312
- "name": "GPT o1-mini",
313
- "integration": "openai",
314
- "input": {
315
- "maxTokens": 128e3
316
- },
317
- "output": {
318
- "maxTokens": 65536
319
- }
320
- },
321
- {
322
- "id": "openai__gpt-3.5-turbo-0125",
323
- "name": "GPT-3.5 Turbo",
324
- "integration": "openai",
325
- "input": {
326
- "maxTokens": 128e3
327
- },
328
- "output": {
329
- "maxTokens": 4096
330
- }
331
- },
332
- {
333
- "id": "openai__gpt-4-turbo-2024-04-09",
334
- "name": "GPT-4 Turbo",
335
- "integration": "openai",
336
- "input": {
337
- "maxTokens": 128e3
338
- },
339
- "output": {
340
- "maxTokens": 4096
341
- }
342
- },
343
- {
344
- "id": "openai__gpt-4o-2024-08-06",
345
- "name": "GPT-4o (August 2024)",
346
- "integration": "openai",
347
- "input": {
348
- "maxTokens": 128e3
349
- },
350
- "output": {
351
- "maxTokens": 16384
352
- }
353
- },
354
- {
355
- "id": "openai__gpt-4o-2024-05-13",
356
- "name": "GPT-4o (May 2024)",
357
- "integration": "openai",
358
- "input": {
359
- "maxTokens": 128e3
360
- },
361
- "output": {
362
- "maxTokens": 4096
363
- }
364
- },
365
- {
366
- "id": "openai__gpt-4o-2024-11-20",
367
- "name": "GPT-4o (November 2024)",
368
- "integration": "openai",
369
- "input": {
370
- "maxTokens": 128e3
371
- },
372
- "output": {
373
- "maxTokens": 16384
374
- }
375
- },
376
- {
377
- "id": "openai__gpt-4o-mini-2024-07-18",
378
- "name": "GPT-4o Mini",
379
- "integration": "openai",
380
- "input": {
381
- "maxTokens": 128e3
382
- },
383
- "output": {
384
- "maxTokens": 16384
385
- }
386
- }
387
- ];
@@ -1,57 +0,0 @@
1
- import { Client } from "@botpress/client";
2
- import _ from "lodash";
3
- import fs from "node:fs";
4
- const LLM_LIST_MODELS = "listLanguageModels";
5
- const client = new Client({
6
- apiUrl: process.env.CLOUD_API_ENDPOINT,
7
- botId: process.env.CLOUD_BOT_ID,
8
- token: process.env.CLOUD_PAT
9
- });
10
- const { bot } = await client.getBot({
11
- id: process.env.CLOUD_BOT_ID
12
- });
13
- const models = [];
14
- for (const integrationId in bot.integrations) {
15
- const botIntegration = bot.integrations[integrationId];
16
- if (botIntegration?.public && botIntegration?.enabled && botIntegration?.status === "registered") {
17
- try {
18
- const { integration } = await client.getPublicIntegrationById({
19
- id: botIntegration.id
20
- });
21
- const canListModels = Object.keys(integration.actions).includes(LLM_LIST_MODELS);
22
- if (!canListModels) {
23
- continue;
24
- }
25
- const { output } = await client.callAction({
26
- type: `${integration.name}:${LLM_LIST_MODELS}`,
27
- input: {}
28
- });
29
- if (_.isArray(output?.models)) {
30
- for (const model of output.models) {
31
- models.push({
32
- id: `${integration.name}__${model.id}`,
33
- name: model.name,
34
- integration: integration.name,
35
- input: { maxTokens: model.input.maxTokens },
36
- output: { maxTokens: model.output.maxTokens }
37
- });
38
- }
39
- }
40
- } catch (err) {
41
- console.error("Error fetching integration:", err instanceof Error ? err.message : `${err}`);
42
- }
43
- }
44
- }
45
- const content = JSON.stringify(_.orderBy(models, ["integration", "name"]), null, 2);
46
- fs.writeFileSync(
47
- "./src/models.ts",
48
- `
49
- // This file is generated. Do not edit it manually.
50
- // See 'scripts/update-models.ts'
51
-
52
- /* eslint-disable */
53
- /* tslint:disable */
54
-
55
- export const Models = ${content} as const`,
56
- "utf-8"
57
- );
@@ -1,41 +0,0 @@
1
- import { Client } from "@botpress/client";
2
- import { z } from "@bpinternal/zui";
3
- import _ from "lodash";
4
- import fs from "node:fs";
5
- import path from "node:path";
6
- const Interfaces = ["llm"];
7
- const client = new Client({
8
- apiUrl: process.env.CLOUD_API_ENDPOINT,
9
- botId: process.env.CLOUD_BOT_ID,
10
- token: process.env.CLOUD_PAT
11
- });
12
- for (const name of Interfaces) {
13
- const { interfaces } = await client.listInterfaces({
14
- name
15
- });
16
- const { interface: latest } = await client.getInterface({
17
- id: _.maxBy(interfaces, "version").id
18
- });
19
- for (const action of Object.keys(latest.actions)) {
20
- const references = Object.keys(latest.entities).reduce((acc, key) => {
21
- return { ...acc, [key]: z.fromJsonSchema(latest.entities?.[key]?.schema) };
22
- }, {});
23
- const input = latest.actions[action]?.input.schema;
24
- const output = latest.actions[action]?.output.schema;
25
- const types = `
26
- // This file is generated. Do not edit it manually.
27
- // See 'scripts/update-models.ts'
28
-
29
- /* eslint-disable */
30
- /* tslint:disable */
31
-
32
- export namespace ${name} {
33
- export namespace ${action} {
34
- export ${z.fromJsonSchema(input).title("Input").dereference(references).toTypescript({ declaration: "type" })};
35
- export ${z.fromJsonSchema(output).title("Output").dereference(references).toTypescript({ declaration: "type" })};
36
- }
37
- }`;
38
- fs.mkdirSync(path.resolve(`./src/sdk-interfaces/${name}`), { recursive: true });
39
- fs.writeFileSync(path.resolve(`./src/sdk-interfaces/${name}/${action}.ts`), types);
40
- }
41
- }