@botpress/zai 1.0.1-beta.1 → 1.0.1-beta.3

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 (47) hide show
  1. package/dist/browser/index.js +4071 -0
  2. package/dist/{csj → node}/adapters/botpress-table.js +1 -2
  3. package/dist/{csj → node}/operations/check.js +1 -2
  4. package/dist/{csj → node}/operations/extract.js +8 -9
  5. package/dist/{csj → node}/operations/filter.js +4 -5
  6. package/dist/{csj → node}/operations/label.js +7 -8
  7. package/dist/{csj → node}/operations/rewrite.js +1 -2
  8. package/dist/{csj → node}/operations/summarize.js +4 -5
  9. package/dist/{csj → node}/operations/text.js +3 -4
  10. package/dist/{csj → node}/utils.js +1 -2
  11. package/dist/{csj → node}/zai.js +1 -2
  12. package/package.json +17 -12
  13. package/scripts/update-models.mts +3 -3
  14. package/scripts/update-types.mts +5 -15
  15. package/src/adapters/botpress-table.ts +3 -4
  16. package/src/operations/__tests/index.ts +1 -0
  17. package/src/operations/check.ts +2 -3
  18. package/src/operations/extract.ts +13 -14
  19. package/src/operations/filter.ts +5 -6
  20. package/src/operations/label.ts +7 -8
  21. package/src/operations/rewrite.ts +3 -4
  22. package/src/operations/summarize.ts +4 -5
  23. package/src/operations/text.ts +4 -5
  24. package/src/utils.ts +1 -2
  25. package/src/zai.ts +4 -4
  26. package/dist/esm/adapters/adapter.js +0 -5
  27. package/dist/esm/adapters/botpress-table.js +0 -194
  28. package/dist/esm/adapters/memory.js +0 -15
  29. package/dist/esm/index.js +0 -11
  30. package/dist/esm/models.js +0 -390
  31. package/dist/esm/operations/check.js +0 -149
  32. package/dist/esm/operations/constants.js +0 -6
  33. package/dist/esm/operations/errors.js +0 -18
  34. package/dist/esm/operations/extract.js +0 -217
  35. package/dist/esm/operations/filter.js +0 -189
  36. package/dist/esm/operations/label.js +0 -246
  37. package/dist/esm/operations/rewrite.js +0 -113
  38. package/dist/esm/operations/summarize.js +0 -134
  39. package/dist/esm/operations/text.js +0 -48
  40. package/dist/esm/utils.js +0 -51
  41. package/dist/esm/zai.js +0 -161
  42. /package/dist/{csj → node}/adapters/adapter.js +0 -0
  43. /package/dist/{csj → node}/adapters/memory.js +0 -0
  44. /package/dist/{csj → node}/index.js +0 -0
  45. /package/dist/{csj → node}/models.js +0 -0
  46. /package/dist/{csj → node}/operations/constants.js +0 -0
  47. /package/dist/{csj → node}/operations/errors.js +0 -0
package/dist/esm/zai.js DELETED
@@ -1,161 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- import sdk from "@botpress/sdk";
22
- import { getWasmTokenizer } from "@botpress/wasm";
23
- import { TableAdapter } from "./adapters/botpress-table";
24
- import { MemoryAdapter } from "./adapters/memory";
25
- import { Models } from "./models";
26
- import { BotpressClient } from "./utils";
27
- const { z } = sdk;
28
- const ActiveLearning = z.object({
29
- enable: z.boolean().describe("Whether to enable active learning").default(false),
30
- tableName: z.string().regex(
31
- /^[A-Za-z0-9_/-]{1,100}Table$/,
32
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
33
- ).describe("The name of the table to store active learning tasks").default("ActiveLearningTable"),
34
- taskId: z.string().regex(
35
- /^[A-Za-z0-9_/-]{1,100}$/,
36
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
37
- ).describe("The ID of the task").default("default")
38
- });
39
- const ZaiConfig = z.object({
40
- client: BotpressClient,
41
- userId: z.string().describe("The ID of the user consuming the API").optional(),
42
- retry: z.object({ maxRetries: z.number().min(0).max(100) }).default({ maxRetries: 3 }),
43
- modelId: z.custom(
44
- (value) => {
45
- if (typeof value !== "string" || !value.includes("__")) {
46
- return false;
47
- }
48
- return true;
49
- },
50
- {
51
- message: "Invalid model ID"
52
- }
53
- ).describe("The ID of the model you want to use").default("openai__gpt-4o-mini-2024-07-18"),
54
- activeLearning: ActiveLearning.default({ enable: false }),
55
- namespace: z.string().regex(
56
- /^[A-Za-z0-9_/-]{1,100}$/,
57
- "Namespace must be alphanumeric and contain only letters, numbers, underscores, hyphens and slashes"
58
- ).default("zai")
59
- });
60
- const _Zai = class _Zai {
61
- constructor(config) {
62
- __publicField(this, "client");
63
- __publicField(this, "originalConfig");
64
- __publicField(this, "userId");
65
- __publicField(this, "integration");
66
- __publicField(this, "model");
67
- __publicField(this, "retry");
68
- __publicField(this, "Model");
69
- __publicField(this, "namespace");
70
- __publicField(this, "adapter");
71
- __publicField(this, "activeLearning");
72
- var _a;
73
- this.originalConfig = config;
74
- const parsed = ZaiConfig.parse(config);
75
- this.client = parsed.client;
76
- const [integration, modelId] = parsed.modelId.split("__");
77
- if (!(integration == null ? void 0 : integration.length) || !(modelId == null ? void 0 : modelId.length)) {
78
- throw new Error(`Invalid model ID: ${parsed.modelId}. Expected format: <integration>__<modelId>`);
79
- }
80
- this.integration = integration;
81
- this.model = modelId;
82
- this.namespace = parsed.namespace;
83
- this.userId = parsed.userId;
84
- this.retry = parsed.retry;
85
- this.Model = Models.find((m) => m.id === parsed.modelId);
86
- this.activeLearning = parsed.activeLearning;
87
- this.adapter = ((_a = parsed.activeLearning) == null ? void 0 : _a.enable) ? new TableAdapter({ client: this.client, tableName: parsed.activeLearning.tableName }) : new MemoryAdapter([]);
88
- }
89
- /** @internal */
90
- async callModel(props) {
91
- let retries = this.retry.maxRetries;
92
- while (retries-- >= 0) {
93
- try {
94
- return await this._callModel(props);
95
- } catch (e) {
96
- if (retries >= 0) {
97
- await new Promise((resolve) => setTimeout(resolve, 1e3));
98
- } else {
99
- throw new Error("Failed to call model after multiple retries");
100
- }
101
- }
102
- }
103
- throw new Error("Failed to call model after multiple retries");
104
- }
105
- /** @internal */
106
- async _callModel(props) {
107
- let retries = this.retry.maxRetries;
108
- do {
109
- const start = Date.now();
110
- const input = __spreadValues({
111
- messages: [],
112
- temperature: 0,
113
- topP: 1,
114
- model: { id: this.model },
115
- userId: this.userId
116
- }, props);
117
- const { output } = await this.client.callAction({
118
- type: `${this.integration}:generateContent`,
119
- input
120
- });
121
- const latency = Date.now() - start;
122
- return __spreadProps(__spreadValues({}, output), {
123
- metadata: {
124
- model: this.model,
125
- latency,
126
- cost: { input: output.usage.inputCost, output: output.usage.outputCost },
127
- tokens: { input: output.usage.inputTokens, output: output.usage.outputTokens }
128
- }
129
- });
130
- } while (--retries > 0);
131
- }
132
- async getTokenizer() {
133
- var _a;
134
- (_a = _Zai.tokenizer) != null ? _a : _Zai.tokenizer = await (async () => {
135
- while (!getWasmTokenizer) {
136
- await new Promise((resolve) => setTimeout(resolve, 25));
137
- }
138
- return getWasmTokenizer();
139
- })();
140
- return _Zai.tokenizer;
141
- }
142
- get taskId() {
143
- if (!this.activeLearning.enable) {
144
- return void 0;
145
- }
146
- return `${this.namespace}/${this.activeLearning.taskId}`.replace(/\/+/g, "/");
147
- }
148
- with(options) {
149
- return new _Zai(__spreadValues(__spreadValues({}, this.originalConfig), options));
150
- }
151
- learn(taskId) {
152
- return new _Zai(__spreadProps(__spreadValues({}, this.originalConfig), {
153
- activeLearning: __spreadProps(__spreadValues({}, this.activeLearning), { taskId, enable: true })
154
- }));
155
- }
156
- };
157
- __publicField(_Zai, "tokenizer", null);
158
- let Zai = _Zai;
159
- export {
160
- Zai
161
- };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes