@botpress/zai 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build.ts +9 -0
- package/dist/adapters/botpress-table.js +21 -21
- package/dist/index.d.ts +27 -517
- package/dist/operations/check.js +22 -6
- package/dist/operations/extract.js +28 -8
- package/dist/operations/filter.js +15 -3
- package/dist/operations/label.js +36 -6
- package/dist/operations/rewrite.js +18 -6
- package/dist/operations/summarize.js +6 -5
- package/dist/operations/text.js +4 -3
- package/dist/utils.js +0 -6
- package/dist/zai.js +28 -68
- package/e2e/data/cache.jsonl +118 -0
- package/{src/operations/__tests/index.ts → e2e/utils.ts} +18 -16
- package/package.json +23 -21
- package/src/adapters/adapter.ts +2 -2
- package/src/adapters/botpress-table.ts +36 -36
- package/src/adapters/memory.ts +3 -3
- package/src/operations/check.ts +53 -20
- package/src/operations/errors.ts +1 -1
- package/src/operations/extract.ts +49 -31
- package/src/operations/filter.ts +36 -23
- package/src/operations/label.ts +73 -25
- package/src/operations/rewrite.ts +28 -15
- package/src/operations/summarize.ts +11 -9
- package/src/operations/text.ts +7 -5
- package/src/utils.ts +5 -14
- package/src/zai.ts +45 -91
- package/tsconfig.json +2 -22
- package/dist/models.js +0 -387
- package/src/models.ts +0 -394
- package/src/operations/__tests/cache.jsonl +0 -101
- package/src/sdk-interfaces/llm/generateContent.ts +0 -127
- package/src/sdk-interfaces/llm/listLanguageModels.ts +0 -19
- /package/{src/operations/__tests → e2e/data}/botpress_docs.txt +0 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ It's built on top of Zui and the Botpress client to interface with the different
|
|
|
10
10
|
import Zai from '@botpress/zai'
|
|
11
11
|
|
|
12
12
|
const zai = new Zai({
|
|
13
|
-
client: new Client({}) // your botpress client here
|
|
13
|
+
client: new Client({}), // your botpress client here
|
|
14
14
|
})
|
|
15
15
|
```
|
|
16
16
|
|
package/build.ts
ADDED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "@bpinternal/zui";
|
|
2
|
-
import {
|
|
2
|
+
import { GenerationMetadata } from "../utils";
|
|
3
3
|
import { Adapter } from "./adapter";
|
|
4
4
|
const CRITICAL_TAGS = {
|
|
5
5
|
system: "true",
|
|
@@ -15,7 +15,7 @@ const OPTIONAL_TAGS = {
|
|
|
15
15
|
};
|
|
16
16
|
const FACTOR = 30;
|
|
17
17
|
const Props = z.object({
|
|
18
|
-
client:
|
|
18
|
+
client: z.custom(() => true),
|
|
19
19
|
tableName: z.string().regex(
|
|
20
20
|
/^[a-zA-Z0-9_]{1,45}Table$/,
|
|
21
21
|
"Table name must be lowercase and contain only letters, numbers and underscores"
|
|
@@ -44,20 +44,20 @@ const TableJsonSchema = Object.entries(TableSchema.shape).reduce((acc, [key, val
|
|
|
44
44
|
return acc;
|
|
45
45
|
}, {});
|
|
46
46
|
export class TableAdapter extends Adapter {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
_client;
|
|
48
|
+
_tableName;
|
|
49
|
+
_status;
|
|
50
50
|
constructor(props) {
|
|
51
51
|
super();
|
|
52
52
|
props = Props.parse(props);
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
55
|
-
this.
|
|
53
|
+
this._client = props.client;
|
|
54
|
+
this._tableName = props.tableName;
|
|
55
|
+
this._status = "ready";
|
|
56
56
|
}
|
|
57
57
|
async getExamples({ taskType, taskId, input }) {
|
|
58
|
-
await this.
|
|
59
|
-
const { rows } = await this.
|
|
60
|
-
table: this.
|
|
58
|
+
await this._assertTableExists();
|
|
59
|
+
const { rows } = await this._client.findTableRows({
|
|
60
|
+
table: this._tableName,
|
|
61
61
|
search: JSON.stringify({ value: input }).substring(0, 1023),
|
|
62
62
|
// Search is limited to 1024 characters
|
|
63
63
|
limit: 10,
|
|
@@ -91,9 +91,9 @@ export class TableAdapter extends Adapter {
|
|
|
91
91
|
metadata,
|
|
92
92
|
status = "pending"
|
|
93
93
|
}) {
|
|
94
|
-
await this.
|
|
95
|
-
await this.
|
|
96
|
-
table: this.
|
|
94
|
+
await this._assertTableExists();
|
|
95
|
+
await this._client.upsertTableRows({
|
|
96
|
+
table: this._tableName,
|
|
97
97
|
keyColumn: "key",
|
|
98
98
|
rows: [
|
|
99
99
|
{
|
|
@@ -111,12 +111,12 @@ export class TableAdapter extends Adapter {
|
|
|
111
111
|
}).catch(() => {
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
async
|
|
115
|
-
if (this.
|
|
114
|
+
async _assertTableExists() {
|
|
115
|
+
if (this._status !== "ready") {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
const { table, created } = await this.
|
|
119
|
-
table: this.
|
|
118
|
+
const { table, created } = await this._client.getOrCreateTable({
|
|
119
|
+
table: this._tableName,
|
|
120
120
|
factor: FACTOR,
|
|
121
121
|
frozen: true,
|
|
122
122
|
isComputeEnabled: false,
|
|
@@ -126,7 +126,7 @@ export class TableAdapter extends Adapter {
|
|
|
126
126
|
},
|
|
127
127
|
schema: TableJsonSchema
|
|
128
128
|
}).catch(() => {
|
|
129
|
-
this.
|
|
129
|
+
this._status = "error";
|
|
130
130
|
return { table: null, created: false };
|
|
131
131
|
});
|
|
132
132
|
if (!table) {
|
|
@@ -160,9 +160,9 @@ export class TableAdapter extends Adapter {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
if (issues.length) {
|
|
163
|
-
this.
|
|
163
|
+
this._status = "error";
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
this.
|
|
166
|
+
this._status = "initialized";
|
|
167
167
|
}
|
|
168
168
|
}
|