@botpress/zai 2.4.0 → 2.4.1

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.
@@ -15,6 +15,7 @@ const Options = z.object({
15
15
  chunkLength: z.number().min(100).max(1e5).optional().describe("The maximum number of tokens per chunk").default(16e3),
16
16
  strict: z.boolean().optional().default(true).describe("Whether to strictly follow the schema or not")
17
17
  });
18
+ const SPECIAL_CHAR = "\u25A0";
18
19
  const START = "\u25A0json_start\u25A0";
19
20
  const END = "\u25A0json_end\u25A0";
20
21
  const NO_MORE = "\u25A0NO_MORE_ELEMENT\u25A0";
@@ -243,7 +244,10 @@ ${instructions.map((x) => `\u2022 ${x}`).join("\n")}
243
244
  ],
244
245
  transform: (text) => (text || "{}")?.split(START).filter((x) => x.trim().length > 0 && x.includes("}")).map((x) => {
245
246
  try {
246
- const json = x.slice(0, x.indexOf(END)).trim();
247
+ let json = x.slice(0, x.indexOf(END)).trim();
248
+ if (json.includes(SPECIAL_CHAR)) {
249
+ json = json.slice(0, json.indexOf(SPECIAL_CHAR)).trim();
250
+ }
247
251
  const repairedJson = jsonrepair(json);
248
252
  const parsedJson = JSON5.parse(repairedJson);
249
253
  const safe = schema.safeParse(parsedJson);
package/package.json CHANGED
@@ -1,7 +1,7 @@
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": "2.4.0",
4
+ "version": "2.4.1",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "exports": {
@@ -45,7 +45,7 @@ declare module '@botpress/zai' {
45
45
  extract<S extends OfType<any>>(input: unknown, schema: S, options?: Options): Response<S['_output']>
46
46
  }
47
47
  }
48
-
48
+ const SPECIAL_CHAR = '■'
49
49
  const START = '■json_start■'
50
50
  const END = '■json_end■'
51
51
  const NO_MORE = '■NO_MORE_ELEMENT■'
@@ -330,7 +330,12 @@ ${instructions.map((x) => `• ${x}`).join('\n')}
330
330
  .filter((x) => x.trim().length > 0 && x.includes('}'))
331
331
  .map((x) => {
332
332
  try {
333
- const json = x.slice(0, x.indexOf(END)).trim()
333
+ let json = x.slice(0, x.indexOf(END)).trim()
334
+
335
+ if (json.includes(SPECIAL_CHAR)) {
336
+ json = json.slice(0, json.indexOf(SPECIAL_CHAR)).trim()
337
+ }
338
+
334
339
  const repairedJson = jsonrepair(json)
335
340
  const parsedJson = JSON5.parse(repairedJson)
336
341
  const safe = schema.safeParse(parsedJson)