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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/dist/{node/adapters → adapters}/botpress-table.js +3 -4
  2. package/dist/index.js +9 -1743
  3. package/dist/{node/operations → operations}/check.js +1 -2
  4. package/dist/{node/operations → operations}/extract.js +1 -2
  5. package/dist/{node/operations → operations}/filter.js +3 -5
  6. package/dist/{node/operations → operations}/label.js +4 -8
  7. package/dist/{node/operations → operations}/rewrite.js +1 -2
  8. package/dist/{node/operations → operations}/summarize.js +1 -2
  9. package/dist/{node/operations → operations}/text.js +1 -2
  10. package/dist/{node/zai.js → zai.js} +2 -3
  11. package/package.json +10 -8
  12. package/dist/browser/index.js +0 -4068
  13. package/dist/node/adapters/adapter.d.js +0 -0
  14. package/dist/node/adapters/botpress-table.d.js +0 -1
  15. package/dist/node/adapters/memory.d.js +0 -0
  16. package/dist/node/index.d.js +0 -9
  17. package/dist/node/index.js +0 -9
  18. package/dist/node/models.d.js +0 -0
  19. package/dist/node/operations/check.d.js +0 -1
  20. package/dist/node/operations/check.test.d.js +0 -1
  21. package/dist/node/operations/constants.d.js +0 -0
  22. package/dist/node/operations/errors.d.js +0 -0
  23. package/dist/node/operations/extract.d.js +0 -1
  24. package/dist/node/operations/extract.test.d.js +0 -1
  25. package/dist/node/operations/filter.d.js +0 -1
  26. package/dist/node/operations/filter.test.d.js +0 -1
  27. package/dist/node/operations/label.d.js +0 -1
  28. package/dist/node/operations/label.test.d.js +0 -1
  29. package/dist/node/operations/rewrite.d.js +0 -1
  30. package/dist/node/operations/rewrite.test.d.js +0 -1
  31. package/dist/node/operations/summarize.d.js +0 -1
  32. package/dist/node/operations/summarize.test.d.js +0 -1
  33. package/dist/node/operations/text.d.js +0 -1
  34. package/dist/node/operations/text.test.d.js +0 -1
  35. package/dist/node/operations/zai-learn.test.d.js +0 -1
  36. package/dist/node/operations/zai-retry.test.d.js +0 -1
  37. package/dist/node/utils.d.js +0 -0
  38. package/dist/node/zai.d.js +0 -1
  39. package/src/adapters/adapter.d.ts +0 -27
  40. package/src/adapters/botpress-table.d.ts +0 -153
  41. package/src/adapters/memory.d.ts +0 -7
  42. package/src/index.d.ts +0 -9
  43. package/src/models.d.ts +0 -351
  44. package/src/operations/__tests/index.d.ts +0 -20
  45. package/src/operations/check.d.ts +0 -36
  46. package/src/operations/check.test.d.ts +0 -1
  47. package/src/operations/constants.d.ts +0 -2
  48. package/src/operations/errors.d.ts +0 -5
  49. package/src/operations/extract.d.ts +0 -20
  50. package/src/operations/extract.test.d.ts +0 -1
  51. package/src/operations/filter.d.ts +0 -39
  52. package/src/operations/filter.test.d.ts +0 -1
  53. package/src/operations/label.d.ts +0 -79
  54. package/src/operations/label.test.d.ts +0 -1
  55. package/src/operations/rewrite.d.ts +0 -34
  56. package/src/operations/rewrite.test.d.ts +0 -1
  57. package/src/operations/summarize.d.ts +0 -46
  58. package/src/operations/summarize.test.d.ts +0 -1
  59. package/src/operations/text.d.ts +0 -16
  60. package/src/operations/text.test.d.ts +0 -1
  61. package/src/operations/zai-learn.test.d.ts +0 -1
  62. package/src/operations/zai-retry.test.d.ts +0 -1
  63. package/src/sdk-interfaces/llm/generateContent.d.ts +0 -128
  64. package/src/sdk-interfaces/llm/listLanguageModels.d.ts +0 -25
  65. package/src/utils.d.ts +0 -52
  66. package/src/zai.d.ts +0 -99
  67. /package/dist/{node/adapters → adapters}/adapter.js +0 -0
  68. /package/dist/{node/adapters → adapters}/memory.js +0 -0
  69. /package/dist/{node/models.js → models.js} +0 -0
  70. /package/dist/{node/operations → operations}/constants.js +0 -0
  71. /package/dist/{node/operations → operations}/errors.js +0 -0
  72. /package/dist/{node/utils.js → utils.js} +0 -0
@@ -14,7 +14,6 @@ const TRUE = "\u25A0TRUE\u25A0";
14
14
  const FALSE = "\u25A0FALSE\u25A0";
15
15
  const END = "\u25A0END\u25A0";
16
16
  Zai.prototype.check = async function(input, condition, _options) {
17
- var _a;
18
17
  const options = Options.parse(_options ?? {});
19
18
  const tokenizer = await this.getTokenizer();
20
19
  const PROMPT_COMPONENT = Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100);
@@ -114,7 +113,7 @@ In your "Analysis", please refer to the Expert Examples # to justify your decisi
114
113
  }
115
114
  ]
116
115
  });
117
- const answer = (_a = output.choices[0]) == null ? void 0 : _a.content;
116
+ const answer = output.choices[0]?.content;
118
117
  const hasTrue = answer.includes(TRUE);
119
118
  const hasFalse = answer.includes(FALSE);
120
119
  if (!hasTrue && !hasFalse) {
@@ -14,7 +14,6 @@ const START = "\u25A0json_start\u25A0";
14
14
  const END = "\u25A0json_end\u25A0";
15
15
  const NO_MORE = "\u25A0NO_MORE_ELEMENT\u25A0";
16
16
  Zai.prototype.extract = async function(input, schema, _options) {
17
- var _a;
18
17
  const options = Options.parse(_options ?? {});
19
18
  const tokenizer = await this.getTokenizer();
20
19
  const taskId = this.taskId;
@@ -179,7 +178,7 @@ ${instructions.map((x) => `\u2022 ${x}`).join("\n")}
179
178
  }
180
179
  ]
181
180
  });
182
- const answer = (_a = output.choices[0]) == null ? void 0 : _a.content;
181
+ const answer = output.choices[0]?.content;
183
182
  const elements = answer.split(START).filter((x) => x.trim().length > 0).map((x) => {
184
183
  try {
185
184
  const json = x.slice(0, x.indexOf(END)).trim();
@@ -96,7 +96,6 @@ ${examples.map((x, idx) => `\u25A0${idx}:${!!x.filter ? "true" : "false"}:${x.re
96
96
  }
97
97
  ];
98
98
  const filterChunk = async (chunk) => {
99
- var _a;
100
99
  const examples = taskId ? await this.adapter.getExamples({
101
100
  // The Table API can't search for a huge input string
102
101
  input: JSON.stringify(chunk).slice(0, 1e3),
@@ -146,14 +145,13 @@ The condition is: "${condition}"
146
145
  }
147
146
  ]
148
147
  });
149
- const answer = (_a = output.choices[0]) == null ? void 0 : _a.content;
148
+ const answer = output.choices[0]?.content;
150
149
  const indices = answer.trim().split("\u25A0").filter((x) => x.length > 0).map((x) => {
151
150
  const [idx, filter] = x.split(":");
152
- return { idx: parseInt((idx == null ? void 0 : idx.trim()) ?? ""), filter: (filter == null ? void 0 : filter.toLowerCase().trim()) === "true" };
151
+ return { idx: parseInt(idx?.trim() ?? ""), filter: filter?.toLowerCase().trim() === "true" };
153
152
  });
154
153
  const partial = chunk.filter((_, idx) => {
155
- var _a2;
156
- return ((_a2 = indices.find((x) => x.idx === idx)) == null ? void 0 : _a2.filter) ?? false;
154
+ return indices.find((x) => x.idx === idx)?.filter ?? false;
157
155
  });
158
156
  if (taskId) {
159
157
  const key = fastHash(
@@ -95,8 +95,7 @@ Zai.prototype.label = async function(input, _labels, _options) {
95
95
  );
96
96
  const convertToAnswer = (mapping) => {
97
97
  return Object.keys(labels).reduce((acc, key) => {
98
- var _a, _b;
99
- acc[key] = ((_a = mapping[key]) == null ? void 0 : _a.label) === "ABSOLUTELY_YES" || ((_b = mapping[key]) == null ? void 0 : _b.label) === "PROBABLY_YES";
98
+ acc[key] = mapping[key]?.label === "ABSOLUTELY_YES" || mapping[key]?.label === "PROBABLY_YES";
100
99
  return acc;
101
100
  }, {});
102
101
  };
@@ -140,12 +139,9 @@ ${stringify(example.input)}
140
139
  Expert Example #${idx + 1}
141
140
  ============
142
141
  ${Object.keys(example.output).map(
143
- (key) => {
144
- var _a, _b;
145
- return `
146
- \u25A0${key}:\u3010${(_a = example.output[key]) == null ? void 0 : _a.explanation}\u3011:${(_b = example.output[key]) == null ? void 0 : _b.label}\u25A0
147
- `.trim();
148
- }
142
+ (key) => `
143
+ \u25A0${key}:\u3010${example.output[key]?.explanation}\u3011:${example.output[key]?.label}\u25A0
144
+ `.trim()
149
145
  ).join("\n")}
150
146
  ${END}
151
147
  `.trim()
@@ -13,7 +13,6 @@ const Options = z.object({
13
13
  const START = "\u25A0START\u25A0";
14
14
  const END = "\u25A0END\u25A0";
15
15
  Zai.prototype.rewrite = async function(original, prompt, _options) {
16
- var _a;
17
16
  const options = Options.parse(_options ?? {});
18
17
  const tokenizer = await this.getTokenizer();
19
18
  const taskId = this.taskId;
@@ -90,7 +89,7 @@ ${instructions.map((x) => `\u2022 ${x}`).join("\n")}
90
89
  maxTokens: options.length,
91
90
  stopSequences: [END]
92
91
  });
93
- let result = (_a = output.choices[0]) == null ? void 0 : _a.content;
92
+ let result = output.choices[0]?.content;
94
93
  if (result.includes(START)) {
95
94
  result = result.slice(result.indexOf(START) + START.length);
96
95
  }
@@ -18,7 +18,6 @@ const Options = z.object({
18
18
  const START = "\u25A0START\u25A0";
19
19
  const END = "\u25A0END\u25A0";
20
20
  Zai.prototype.summarize = async function(original, _options) {
21
- var _a;
22
21
  const options = Options.parse(_options ?? {});
23
22
  const tokenizer = await this.getTokenizer();
24
23
  const INPUT_COMPONENT_SIZE = Math.max(100, (this.Model.input.maxTokens - PROMPT_INPUT_BUFFER) / 4);
@@ -119,7 +118,7 @@ ${options.format}
119
118
  maxTokens: generationLength,
120
119
  stopSequences: [END]
121
120
  });
122
- let result = (_a = output == null ? void 0 : output.choices[0]) == null ? void 0 : _a.content;
121
+ let result = output?.choices[0]?.content;
123
122
  if (result.includes(START)) {
124
123
  result = result.slice(result.indexOf(START) + START.length);
125
124
  }
@@ -6,7 +6,6 @@ const Options = z.object({
6
6
  length: z.number().min(1).max(1e5).optional().describe("The maximum number of tokens to generate")
7
7
  });
8
8
  Zai.prototype.text = async function(prompt, _options) {
9
- var _a, _b;
10
9
  const options = Options.parse(_options ?? {});
11
10
  const tokenizer = await this.getTokenizer();
12
11
  prompt = tokenizer.truncate(prompt, Math.max(this.Model.input.maxTokens - PROMPT_INPUT_BUFFER, 100));
@@ -43,5 +42,5 @@ ${chart}
43
42
  messages: [{ type: "text", content: prompt, role: "user" }],
44
43
  maxTokens: options.length
45
44
  });
46
- return (_b = (_a = output == null ? void 0 : output.choices) == null ? void 0 : _a[0]) == null ? void 0 : _b.content;
45
+ return output?.choices?.[0]?.content;
47
46
  };
@@ -49,12 +49,11 @@ export class Zai {
49
49
  adapter;
50
50
  activeLearning;
51
51
  constructor(config) {
52
- var _a;
53
52
  this.originalConfig = config;
54
53
  const parsed = ZaiConfig.parse(config);
55
54
  this.client = parsed.client;
56
55
  const [integration, modelId] = parsed.modelId.split("__");
57
- if (!(integration == null ? void 0 : integration.length) || !(modelId == null ? void 0 : modelId.length)) {
56
+ if (!integration?.length || !modelId?.length) {
58
57
  throw new Error(`Invalid model ID: ${parsed.modelId}. Expected format: <integration>__<modelId>`);
59
58
  }
60
59
  this.integration = integration;
@@ -64,7 +63,7 @@ export class Zai {
64
63
  this.retry = parsed.retry;
65
64
  this.Model = Models.find((m) => m.id === parsed.modelId);
66
65
  this.activeLearning = parsed.activeLearning;
67
- this.adapter = ((_a = parsed.activeLearning) == null ? void 0 : _a.enable) ? new TableAdapter({ client: this.client, tableName: parsed.activeLearning.tableName }) : new MemoryAdapter([]);
66
+ this.adapter = parsed.activeLearning?.enable ? new TableAdapter({ client: this.client, tableName: parsed.activeLearning.tableName }) : new MemoryAdapter([]);
68
67
  }
69
68
  /** @internal */
70
69
  async callModel(props) {
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@botpress/zai",
3
3
  "description": "Zui AI (zai) – An LLM utility library written on top of Zui and the Botpress API",
4
- "version": "1.0.1-beta.5",
5
- "main": "./dist/node/index.js",
6
- "browser": "./dist/browser/index.js",
4
+ "version": "1.0.1-beta.8",
5
+ "main": "./dist/index.js",
7
6
  "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ "types": "./dist/index.d.ts",
9
+ "require": "./dist/index.js",
10
+ "import": "./dist/index.js"
11
+ },
8
12
  "scripts": {
9
- "build": "npm run build:types && npm run build:nodejs && npm run build:browser",
10
- "build:nodejs": "esbuild src/**/*.ts src/*.ts --platform=node --target=node16 --outdir=dist/node",
11
- "build:browser": "esbuild src/index.ts --bundle --external:@bpinternal/zui --external:@botpress/client --external:@botpress/wasm --platform=browser --target=chrome58,firefox57,safari11 --outdir=dist/browser",
12
- "build:types": "tsup",
13
+ "build": "npm run build:types && npm run build:neutral",
14
+ "build:neutral": "esbuild src/**/*.ts src/*.ts --platform=neutral --outdir=dist",
15
+ "build:types": "",
13
16
  "watch": "tsup --watch",
14
17
  "test": "vitest run --config vitest.config.ts",
15
18
  "test:update": "vitest -u run --config vitest.config.ts",
@@ -28,7 +31,6 @@
28
31
  },
29
32
  "devDependencies": {
30
33
  "@botpress/vai": "0.0.1-beta.7",
31
- "@microsoft/api-extractor": "^7.48.1",
32
34
  "@types/lodash-es": "^4.17.0",
33
35
  "dotenv": "^16.3.1",
34
36
  "esbuild": "^0.24.2",