@botpress/zai 1.0.1-beta.5 → 1.0.1-beta.7
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/{node/adapters → adapters}/botpress-table.js +3 -4
- package/dist/index.js +9 -1743
- package/dist/{node/operations → operations}/check.js +1 -2
- package/dist/{node/operations → operations}/extract.js +1 -2
- package/dist/{node/operations → operations}/filter.js +3 -5
- package/dist/{node/operations → operations}/label.js +4 -8
- package/dist/{node/operations → operations}/rewrite.js +1 -2
- package/dist/{node/operations → operations}/summarize.js +1 -2
- package/dist/{node/operations → operations}/text.js +1 -2
- package/dist/{node/zai.js → zai.js} +2 -3
- package/package.json +5 -8
- package/dist/browser/index.js +0 -4068
- package/dist/node/adapters/adapter.d.js +0 -0
- package/dist/node/adapters/botpress-table.d.js +0 -1
- package/dist/node/adapters/memory.d.js +0 -0
- package/dist/node/index.d.js +0 -9
- package/dist/node/index.js +0 -9
- package/dist/node/models.d.js +0 -0
- package/dist/node/operations/check.d.js +0 -1
- package/dist/node/operations/check.test.d.js +0 -1
- package/dist/node/operations/constants.d.js +0 -0
- package/dist/node/operations/errors.d.js +0 -0
- package/dist/node/operations/extract.d.js +0 -1
- package/dist/node/operations/extract.test.d.js +0 -1
- package/dist/node/operations/filter.d.js +0 -1
- package/dist/node/operations/filter.test.d.js +0 -1
- package/dist/node/operations/label.d.js +0 -1
- package/dist/node/operations/label.test.d.js +0 -1
- package/dist/node/operations/rewrite.d.js +0 -1
- package/dist/node/operations/rewrite.test.d.js +0 -1
- package/dist/node/operations/summarize.d.js +0 -1
- package/dist/node/operations/summarize.test.d.js +0 -1
- package/dist/node/operations/text.d.js +0 -1
- package/dist/node/operations/text.test.d.js +0 -1
- package/dist/node/operations/zai-learn.test.d.js +0 -1
- package/dist/node/operations/zai-retry.test.d.js +0 -1
- package/dist/node/utils.d.js +0 -0
- package/dist/node/zai.d.js +0 -1
- package/src/adapters/adapter.d.ts +0 -27
- package/src/adapters/botpress-table.d.ts +0 -153
- package/src/adapters/memory.d.ts +0 -7
- package/src/index.d.ts +0 -9
- package/src/models.d.ts +0 -351
- package/src/operations/__tests/index.d.ts +0 -20
- package/src/operations/check.d.ts +0 -36
- package/src/operations/check.test.d.ts +0 -1
- package/src/operations/constants.d.ts +0 -2
- package/src/operations/errors.d.ts +0 -5
- package/src/operations/extract.d.ts +0 -20
- package/src/operations/extract.test.d.ts +0 -1
- package/src/operations/filter.d.ts +0 -39
- package/src/operations/filter.test.d.ts +0 -1
- package/src/operations/label.d.ts +0 -79
- package/src/operations/label.test.d.ts +0 -1
- package/src/operations/rewrite.d.ts +0 -34
- package/src/operations/rewrite.test.d.ts +0 -1
- package/src/operations/summarize.d.ts +0 -46
- package/src/operations/summarize.test.d.ts +0 -1
- package/src/operations/text.d.ts +0 -16
- package/src/operations/text.test.d.ts +0 -1
- package/src/operations/zai-learn.test.d.ts +0 -1
- package/src/operations/zai-retry.test.d.ts +0 -1
- package/src/sdk-interfaces/llm/generateContent.d.ts +0 -128
- package/src/sdk-interfaces/llm/listLanguageModels.d.ts +0 -25
- package/src/utils.d.ts +0 -52
- package/src/zai.d.ts +0 -99
- /package/dist/{node/adapters → adapters}/adapter.js +0 -0
- /package/dist/{node/adapters → adapters}/memory.js +0 -0
- /package/dist/{node/models.js → models.js} +0 -0
- /package/dist/{node/operations → operations}/constants.js +0 -0
- /package/dist/{node/operations → operations}/errors.js +0 -0
- /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 =
|
|
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 =
|
|
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 =
|
|
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(
|
|
151
|
+
return { idx: parseInt(idx?.trim() ?? ""), filter: filter?.toLowerCase().trim() === "true" };
|
|
153
152
|
});
|
|
154
153
|
const partial = chunk.filter((_, idx) => {
|
|
155
|
-
|
|
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
|
-
|
|
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
|
-
|
|
145
|
-
|
|
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 =
|
|
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 =
|
|
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
|
|
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 (!
|
|
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 =
|
|
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,13 @@
|
|
|
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
|
-
"main": "./dist/
|
|
6
|
-
"browser": "./dist/browser/index.js",
|
|
4
|
+
"version": "1.0.1-beta.7",
|
|
5
|
+
"main": "./dist/index.js",
|
|
7
6
|
"types": "./dist/index.d.ts",
|
|
8
7
|
"scripts": {
|
|
9
|
-
"build": "npm run build:types && npm run build:
|
|
10
|
-
"build:
|
|
11
|
-
"build:
|
|
12
|
-
"build:types": "tsup",
|
|
8
|
+
"build": "npm run build:types && npm run build:neutral",
|
|
9
|
+
"build:neutral": "esbuild src/**/*.ts src/*.ts --platform=neutral --outdir=dist",
|
|
10
|
+
"build:types": "",
|
|
13
11
|
"watch": "tsup --watch",
|
|
14
12
|
"test": "vitest run --config vitest.config.ts",
|
|
15
13
|
"test:update": "vitest -u run --config vitest.config.ts",
|
|
@@ -28,7 +26,6 @@
|
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
28
|
"@botpress/vai": "0.0.1-beta.7",
|
|
31
|
-
"@microsoft/api-extractor": "^7.48.1",
|
|
32
29
|
"@types/lodash-es": "^4.17.0",
|
|
33
30
|
"dotenv": "^16.3.1",
|
|
34
31
|
"esbuild": "^0.24.2",
|