@botpress/vai 0.0.1-beta.4 → 0.0.1-beta.5
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -392,7 +392,7 @@ function filter(values, condition, options) {
|
|
|
392
392
|
var _a, _b;
|
|
393
393
|
const mappedValues = values.map(
|
|
394
394
|
(_, idx) => import_sdk4.z.object({
|
|
395
|
-
index:
|
|
395
|
+
index: import_sdk4.z.literal(idx),
|
|
396
396
|
reason: import_sdk4.z.string(),
|
|
397
397
|
keep: import_sdk4.z.boolean()
|
|
398
398
|
})
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/task/compare.ts","../src/utils/deferred.ts","../src/assertions/check.ts","../src/context.ts","../src/utils/asyncAssertion.ts","../src/utils/predictJson.ts","../src/assertions/extension.ts","../src/assertions/extract.ts","../src/assertions/filter.ts","../src/assertions/rate.ts","../src/hooks/setEvaluator.ts","../src/hooks/setupClient.ts"],"sourcesContent":["export { compare } from './task/compare'\n\nexport { check } from './assertions/check'\nexport { extract } from './assertions/extract'\nexport { filter } from './assertions/filter'\nexport { rate } from './assertions/rate'\n\nexport { setEvaluator } from './hooks/setEvaluator'\nexport { setupClient } from './hooks/setupClient'\n","import { z } from '@botpress/sdk'\nimport { TestFunction } from 'vitest'\nimport { createTaskCollector, getCurrentSuite } from 'vitest/suite'\nimport { TestMetadata } from '../context'\nimport { Deferred } from '../utils/deferred'\n\nconst scenarioId = z\n .string()\n .trim()\n .min(1, 'Scenario ID/name must not be empty')\n .max(50, 'Scenario ID/name is too long')\n\nexport type ScenarioLike = z.infer<typeof ScenarioLike>\nconst ScenarioLike = z.union([\n scenarioId,\n z.object({ name: scenarioId }).passthrough(),\n z.object({ id: scenarioId }).passthrough()\n])\n\nconst getScenarioName = (scenario: ScenarioLike) =>\n (typeof scenario === 'string' ? scenario : 'name' in scenario ? scenario?.name : scenario?.id) as string\n\nconst scenarioArgs = z\n .array(ScenarioLike)\n .min(2, 'You need at least two scenarios to compare')\n .max(10, 'You can only compare up to 10 scenarios')\n .refine((scenarios) => {\n const set = new Set<string>()\n scenarios.forEach((scenario) => set.add(getScenarioName(scenario)))\n return set.size === scenarios.length\n }, 'Scenarios names must be unique')\n\nexport function compare<T extends ReadonlyArray<ScenarioLike>>(\n name: string | Function,\n scenarios: T,\n fn?: TestFunction<{\n scenario: T[number]\n }>\n) {\n scenarios = scenarioArgs.parse(scenarios) as unknown as T\n\n return createTaskCollector((_name, fn, timeout) => {\n const currentSuite = getCurrentSuite()\n\n let completedCount = 0\n const finished = new Deferred<void>()\n\n for (const scenario of scenarios) {\n const key = getScenarioName(scenario)\n\n currentSuite.task(key, {\n meta: {\n scenario: key,\n isVaiTest: true\n } satisfies TestMetadata,\n handler: async (context) => {\n const extendedContext = Object.freeze({\n scenario\n })\n context.onTestFinished(() => {\n if (++completedCount === scenarios.length) {\n finished.resolve()\n }\n })\n\n await fn({ ...context, ...extendedContext })\n },\n timeout: timeout ?? 10_000\n })\n }\n })(name, fn)\n}\n","export class Deferred<T> {\n promise: Promise<T>\n private _resolve!: (value: T | PromiseLike<T>) => void\n private _reject!: (reason?: unknown) => void\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve\n this._reject = reject\n })\n }\n\n resolve(value: T | PromiseLike<T>): void {\n this._resolve(value)\n }\n\n reject(reason?: unknown): void {\n this._reject(reason)\n }\n}\n","import { z } from '@botpress/sdk'\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type CheckOptions<T> = {\n examples?: { value: T; expected: boolean; reason: string }[]\n}\n\nexport function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>) {\n const promise = predictJson({\n systemMessage: `Check that the value meets the condition: ${condition}`,\n examples: options?.examples?.map(({ value, reason, expected }) => ({\n input: value,\n output: { reason, result: expected }\n })),\n outputSchema: z.boolean(),\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: boolean) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import type { Client } from '@botpress/client'\nimport { onTestFinished } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Models } from './models'\n\nexport type EvaluatorModel = (typeof Models)[number]['id']\n\nexport type TestMetadata = {\n isVaiTest: boolean\n scenario?: string\n evaluatorModel?: EvaluatorModel\n}\n\nconst getTestMetadata = (): TestMetadata => {\n const test = getCurrentTest()\n return (test?.meta ?? {\n isVaiTest: false\n }) as TestMetadata\n}\n\nclass VaiContext {\n #client: Client | null = null\n #wrapError = false\n\n get wrapError() {\n return this.#wrapError\n }\n\n get client() {\n if (!this.#client) {\n throw new Error('Botpress client is not set')\n }\n\n return this.#client\n }\n\n get evaluatorModel(): EvaluatorModel {\n return getTestMetadata().evaluatorModel ?? 'openai__gpt-4o-mini-2024-07-18'\n }\n\n get scenario() {\n return getTestMetadata().scenario\n }\n\n get isVaiTest() {\n return getTestMetadata().isVaiTest\n }\n\n setClient(cognitive: Client) {\n this.#client = cognitive\n }\n\n swallowErrors() {\n if (!getCurrentTest()) {\n throw new Error('cancelBail is a Vitest hook and must be called within a test')\n }\n\n this.#wrapError = true\n onTestFinished(() => {\n this.#wrapError = false\n })\n }\n}\n\nexport const Context = new VaiContext()\n","import { Assertion, expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Context } from '../context'\nimport { Output } from './predictJson'\n\nexport class AsyncExpectError<T> extends Error {\n constructor(message: string, public readonly output: Output<T>) {\n super(message)\n this.name = 'AsyncExpectError'\n }\n}\n\nconst getErrorMessages = (e: unknown): string => {\n if (e instanceof Error) {\n return e.message\n } else if (typeof e === 'string') {\n return e\n } else if (typeof e === 'object' && e !== null) {\n return JSON.stringify(e)\n }\n\n return `Unknown error: ${e}`\n}\n\nexport const asyncExpect = <T>(output: Promise<Output<T>>, assertion: (assert: Assertion<T>) => void) => {\n const promise = output.then((x) => {\n try {\n assertion(expect(x.result, x.reason))\n } catch (e: unknown) {\n if (Context.wrapError) {\n return new AsyncExpectError<T>(getErrorMessages(e), x)\n }\n throw e\n }\n return x\n })\n getCurrentTest()!.promises ??= []\n getCurrentTest()!.promises!.push(promise)\n return promise\n}\n","import { z, type ZodSchema } from '@botpress/sdk'\nimport JSON5 from 'json5'\nimport { Context } from '../context'\nimport { llm } from '../sdk-interfaces/llm/generateContent'\n\nconst nonEmptyString = z.string().trim().min(1)\nconst nonEmptyObject = z\n .object({})\n .passthrough()\n .refine((value) => Object.keys(value).length > 0, {\n message: 'Expected a non-empty object'\n })\n\nexport type Input = z.infer<typeof Input>\nconst Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()))\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Output<T = any> = z.infer<typeof Output> & { result: T }\nconst Output = z.object({\n reason: nonEmptyString.describe('A human-readable explanation of the result'),\n result: z\n .any()\n .describe(\n 'Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above'\n )\n})\n\ntype Example = z.infer<typeof Example>\nconst Example = z.object({\n input: Input,\n output: Output\n})\n\ntype InputOptions<T extends ZodSchema = ZodSchema> = z.input<typeof Options> & { outputSchema: T }\ntype Options = z.infer<typeof Options>\nconst Options = z.object({\n systemMessage: z.string(),\n examples: z.array(Example).default([]),\n input: Input,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema: z.custom<ZodSchema<any>>((value) => typeof value === 'object' && value !== null && '_def' in value),\n model: z.string()\n})\n\ntype Message = {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\nconst isValidExample =\n (outputSchema: ZodSchema) =>\n (example: Example): example is Example =>\n Input.safeParse(example.input).success &&\n Output.safeParse(example.output).success &&\n outputSchema.safeParse(example.output.result).success\n\nexport async function predictJson<T extends ZodSchema>(_options: InputOptions<T>): Promise<Output<z.infer<T>>> {\n const options = Options.parse(_options)\n const [integration, model] = options.model.split('__')\n\n if (!model?.length) {\n throw new Error('Invalid model')\n }\n\n const exampleMessages = options.examples\n .filter(isValidExample(options.outputSchema))\n .flatMap(({ input, output }) => [\n { role: 'user', content: JSON.stringify(input, null, 2) } satisfies Message,\n { role: 'assistant', content: JSON.stringify(output, null, 2) } satisfies Message\n ])\n\n const outputSchema = Output.extend({\n result: options.outputSchema.describe(Output.shape.result.description!)\n })\n\n const result = await Context.client.callAction({\n type: `${integration}:generateContent`,\n input: {\n systemPrompt: `\n${options.systemMessage}\n\n---\nPlease generate a JSON response with the following format:\n\\`\\`\\`typescript\n${await outputSchema.toTypescriptAsync()}\n\\`\\`\\`\n`.trim(),\n messages: [\n ...exampleMessages,\n {\n role: 'user',\n content: JSON.stringify(options.input, null, 2)\n }\n ],\n temperature: 0,\n responseFormat: 'json_object',\n model: { id: model! }\n } satisfies llm.generateContent.Input\n })\n\n const output = result.output as llm.generateContent.Output\n\n if (!output.choices.length || typeof output.choices?.[0]?.content !== 'string') {\n throw new Error('Invalid response from the model')\n }\n\n const json = output.choices[0].content.trim()\n\n if (!json.length) {\n throw new Error('No response from the model')\n }\n\n return outputSchema.parse(JSON5.parse(json)) as Output<z.infer<T>>\n}\n","import json5 from 'json5'\nimport { expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\n\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Output } from '../utils/predictJson'\n\nexport type ExtendedPromise<T> = PromiseLike<Output<T>> & {\n value: PromiseLike<T>\n}\n\nexport const toAssertion = <T>(promise: Promise<Output<T>>): ExtendedPromise<T> => {\n return {\n then: promise.then.bind(promise),\n value: promise.then((value) => value.result)\n }\n}\n\nexport const makeToMatchInlineSnapshot =\n <T>(promise: Promise<Output<T>>) =>\n async (expected?: string) => {\n const stack = new Error().stack!.split('\\n')[2]\n const newStack = `\nat __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)\nat randomLine (node:internal/process/task_queues:1:1)\n${stack}\n`.trim()\n\n const obj = json5.parse(expected ?? '\"\"')\n const expectation = asyncExpect(promise, (expect) => expect.toMatchObject(obj)).catch(() => {\n // we swallow the error here, as we're going to throw a new one with the correct stack\n // this is just to make vitest happy and show a nice error message\n })\n\n try {\n expect((await promise).result).toMatchObject(obj)\n } catch (err) {\n const newError = new Error()\n newError.stack = newStack\n\n expect.getState().snapshotState.match({\n isInline: true,\n received: (await promise).result,\n testName: getCurrentTest()!.name,\n error: newError,\n inlineSnapshot: expected\n })\n }\n\n return expectation\n }\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type ExtractOptions<T, S> = {\n description?: string\n examples?: { value: T; extracted: S; reason: string }[]\n}\n\nexport function extract<T extends Input, S extends z.AnyZodObject>(\n value: T,\n shape: S,\n options?: ExtractOptions<T, z.infer<S>>\n) {\n const additionalMessage = options?.description\n ? `\\nIn order to extract the right information, follow these instructions:\\n${options.description}\\n`\n : ''\n const promise = predictJson({\n systemMessage:\n 'From the given input, extract the required information into the requested format.' + additionalMessage.trim(),\n examples: options?.examples?.map(({ value, reason, extracted }) => ({\n input: value,\n output: { reason, result: extracted }\n })),\n outputSchema: shape,\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: z.infer<S>) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchObject: (expected: Partial<z.infer<S>>) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { literal, z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type FilterOptions<T> = {\n examples?: { value: T; reason: string; keep: boolean }[]\n}\n\nexport function filter<U>(values: U[], condition: string, options?: FilterOptions<U>) {\n const mappedValues = values.map((_, idx) =>\n z.object({\n index: literal(idx),\n reason: z.string(),\n keep: z.boolean()\n })\n )\n\n const input = values.map((value, idx) => ({\n index: idx,\n value\n }))\n\n const schema = z\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .tuple(mappedValues as any)\n .describe(\n 'An array of the objects with the index and a boolean value indicating if the object should be kept or not'\n )\n\n const promise = predictJson({\n systemMessage: `\nBased on the following qualification criteria, you need to filter the given list of objects.\nCiteria: ${condition}\n\n---\nYou need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.\n`.trim(),\n examples: options?.examples\n ? [\n {\n input: options?.examples?.map((v, index) => ({\n index,\n value: v.value\n })),\n output: {\n reason: 'Here are some examples',\n result: options?.examples?.map((v, idx) => ({\n index: idx,\n reason: v.reason,\n keep: v.keep\n }))\n }\n }\n ]\n : undefined,\n outputSchema: schema,\n model: Context.evaluatorModel,\n input\n }).then((x) => {\n const results = schema.parse(x.result) as { index: number; keep: boolean }[]\n return {\n result: values.filter((_, idx) => results.find((r) => r.index === idx)?.keep),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: U[]) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toHaveNoneFiltered: () => asyncExpect(promise, (expect) => expect.toEqual(values)),\n toHaveSomeFiltered: () => asyncExpect(promise, (expect) => expect.not.toEqual(values)),\n toBeEmpty: () => asyncExpect(promise, (expect) => expect.toHaveLength(0)),\n length: {\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toHaveLength(expected)),\n toBeGreaterThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.greaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.lessThanOrEqual(expected)),\n toBeBetween: (min: number, max: number) => asyncExpect(promise, (expect) => expect.length.within(min, max))\n }\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type RatingScore = 1 | 2 | 3 | 4 | 5\nexport type RateOptions<T> = {\n examples?: { value: T; rating: number; reason: string }[]\n}\n\nexport function rate<T extends Input>(value: T, condition: string, options?: RateOptions<T>) {\n const schema = z.number().min(1).max(5).describe('Rating score, higher is better (1 is the worst, 5 is the best)')\n const promise = predictJson({\n systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.\\nScoring: 1 is the worst score, 5 is the best score possible.\\nCriteria: ${condition}`,\n examples: options?.examples?.map(({ value, reason, rating }) => ({\n input: value,\n output: { reason, result: rating }\n })),\n outputSchema: schema,\n model: Context.evaluatorModel,\n input: value\n }).then((x) => {\n return {\n result: typeof x.result === 'number' ? x.result : parseInt(x.result, 10),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toBeGreaterThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeGreaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeLessThanOrEqual(expected))\n }\n}\n","import { getCurrentTest } from 'vitest/suite'\nimport { EvaluatorModel, TestMetadata } from '../context'\n\nexport const setEvaluator = (model: EvaluatorModel) => {\n const test = getCurrentTest()\n\n if (!test) {\n throw new Error('setEvaluator is a Vitest hook and must be called within a test')\n }\n\n const meta = test.meta as TestMetadata\n meta.evaluatorModel = model\n}\n","import { Client } from '@botpress/client'\nimport { Context } from '../context'\n\nexport const setupClient = (client: Client) => {\n Context.setClient(client)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAElB,mBAAqD;;;ACF9C,IAAM,YAAN,MAAM,UAAY;AAAA,EAKvB,cAAc;AACZ,SAAK,UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AACjD,WAAK,WAAW;AAChB,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,OAAiC;AACvC,SAAK,SAAS,KAAK;AAAA,EACrB;AAAA,EAEA,OAAO,QAAwB;AAC7B,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAnByB;AAAlB,IAAM,WAAN;;;ADMP,IAAM,aAAa,aAChB,OAAO,EACP,KAAK,EACL,IAAI,GAAG,oCAAoC,EAC3C,IAAI,IAAI,8BAA8B;AAGzC,IAAM,eAAe,aAAE,MAAM;AAAA,EAC3B;AAAA,EACA,aAAE,OAAO,EAAE,MAAM,WAAW,CAAC,EAAE,YAAY;AAAA,EAC3C,aAAE,OAAO,EAAE,IAAI,WAAW,CAAC,EAAE,YAAY;AAC3C,CAAC;AAED,IAAM,kBAAkB,wBAAC,aACtB,OAAO,aAAa,WAAW,WAAW,UAAU,WAAW,qCAAU,OAAO,qCAAU,IADrE;AAGxB,IAAM,eAAe,aAClB,MAAM,YAAY,EAClB,IAAI,GAAG,4CAA4C,EACnD,IAAI,IAAI,yCAAyC,EACjD,OAAO,CAAC,cAAc;AACrB,QAAM,MAAM,oBAAI,IAAY;AAC5B,YAAU,QAAQ,CAAC,aAAa,IAAI,IAAI,gBAAgB,QAAQ,CAAC,CAAC;AAClE,SAAO,IAAI,SAA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AQ,OAAO,EAAE,WAAW,WAAW,EAAE,SAAS,SAAS,EAAE,QAAQ,EAAE;AAAA,MACvE,QAAQ,EAAE;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO,iCACF,YAAY,OAAO,IADjB;AAAA,IAEL,MAAM,wBAAC,aAAqB,YAAY,SAAS,CAACC,YAAWA,QAAO,QAAQ,QAAQ,CAAC,GAA/E;AAAA,IACN,uBAAuB,0BAA0B,OAAO;AAAA,IACxD,wBAAwB,wBAAC,aACvB,YAAY,SAAS,CAACA,YAAWA,QAAO,uBAAuB,QAAQ,CAAC,GADlD;AAAA,IAExB,qBAAqB,wBAAC,aACpB,YAAY,SAAS,CAACA,YAAWA,QAAO,oBAAoB,QAAQ,CAAC,GADlD;AAAA,EAEvB;AACF;AA3BgB;;;ACZhB,IAAAC,gBAA+B;AAGxB,IAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,WAAO,8BAAe;AAE5B,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,gEAAgE;AAAA,EAClF;AAEA,QAAM,OAAO,KAAK;AAClB,OAAK,iBAAiB;AACxB,GAT4B;;;ACArB,IAAM,cAAc,wBAAC,WAAmB;AAC7C,UAAQ,UAAU,MAAM;AAC1B,GAF2B;","names":["fn","import_sdk","import_suite","import_vitest","import_suite","import_sdk","output","JSON5","import_json5","import_vitest","import_suite","json5","expect","value","expect","value","expect","import_sdk","_a","expect","import_sdk","value","expect","import_suite"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/task/compare.ts","../src/utils/deferred.ts","../src/assertions/check.ts","../src/context.ts","../src/utils/asyncAssertion.ts","../src/utils/predictJson.ts","../src/assertions/extension.ts","../src/assertions/extract.ts","../src/assertions/filter.ts","../src/assertions/rate.ts","../src/hooks/setEvaluator.ts","../src/hooks/setupClient.ts"],"sourcesContent":["export { compare } from './task/compare'\n\nexport { check } from './assertions/check'\nexport { extract } from './assertions/extract'\nexport { filter } from './assertions/filter'\nexport { rate } from './assertions/rate'\n\nexport { setEvaluator } from './hooks/setEvaluator'\nexport { setupClient } from './hooks/setupClient'\n","import { z } from '@botpress/sdk'\nimport { TestFunction } from 'vitest'\nimport { createTaskCollector, getCurrentSuite } from 'vitest/suite'\nimport { TestMetadata } from '../context'\nimport { Deferred } from '../utils/deferred'\n\nconst scenarioId = z\n .string()\n .trim()\n .min(1, 'Scenario ID/name must not be empty')\n .max(50, 'Scenario ID/name is too long')\n\nexport type ScenarioLike = z.infer<typeof ScenarioLike>\nconst ScenarioLike = z.union([\n scenarioId,\n z.object({ name: scenarioId }).passthrough(),\n z.object({ id: scenarioId }).passthrough()\n])\n\nconst getScenarioName = (scenario: ScenarioLike) =>\n (typeof scenario === 'string' ? scenario : 'name' in scenario ? scenario?.name : scenario?.id) as string\n\nconst scenarioArgs = z\n .array(ScenarioLike)\n .min(2, 'You need at least two scenarios to compare')\n .max(10, 'You can only compare up to 10 scenarios')\n .refine((scenarios) => {\n const set = new Set<string>()\n scenarios.forEach((scenario) => set.add(getScenarioName(scenario)))\n return set.size === scenarios.length\n }, 'Scenarios names must be unique')\n\nexport function compare<T extends ReadonlyArray<ScenarioLike>>(\n name: string | Function,\n scenarios: T,\n fn?: TestFunction<{\n scenario: T[number]\n }>\n) {\n scenarios = scenarioArgs.parse(scenarios) as unknown as T\n\n return createTaskCollector((_name, fn, timeout) => {\n const currentSuite = getCurrentSuite()\n\n let completedCount = 0\n const finished = new Deferred<void>()\n\n for (const scenario of scenarios) {\n const key = getScenarioName(scenario)\n\n currentSuite.task(key, {\n meta: {\n scenario: key,\n isVaiTest: true\n } satisfies TestMetadata,\n handler: async (context) => {\n const extendedContext = Object.freeze({\n scenario\n })\n context.onTestFinished(() => {\n if (++completedCount === scenarios.length) {\n finished.resolve()\n }\n })\n\n await fn({ ...context, ...extendedContext })\n },\n timeout: timeout ?? 10_000\n })\n }\n })(name, fn)\n}\n","export class Deferred<T> {\n promise: Promise<T>\n private _resolve!: (value: T | PromiseLike<T>) => void\n private _reject!: (reason?: unknown) => void\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve\n this._reject = reject\n })\n }\n\n resolve(value: T | PromiseLike<T>): void {\n this._resolve(value)\n }\n\n reject(reason?: unknown): void {\n this._reject(reason)\n }\n}\n","import { z } from '@botpress/sdk'\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type CheckOptions<T> = {\n examples?: { value: T; expected: boolean; reason: string }[]\n}\n\nexport function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>) {\n const promise = predictJson({\n systemMessage: `Check that the value meets the condition: ${condition}`,\n examples: options?.examples?.map(({ value, reason, expected }) => ({\n input: value,\n output: { reason, result: expected }\n })),\n outputSchema: z.boolean(),\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: boolean) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import type { Client } from '@botpress/client'\nimport { onTestFinished } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Models } from './models'\n\nexport type EvaluatorModel = (typeof Models)[number]['id']\n\nexport type TestMetadata = {\n isVaiTest: boolean\n scenario?: string\n evaluatorModel?: EvaluatorModel\n}\n\nconst getTestMetadata = (): TestMetadata => {\n const test = getCurrentTest()\n return (test?.meta ?? {\n isVaiTest: false\n }) as TestMetadata\n}\n\nclass VaiContext {\n #client: Client | null = null\n #wrapError = false\n\n get wrapError() {\n return this.#wrapError\n }\n\n get client() {\n if (!this.#client) {\n throw new Error('Botpress client is not set')\n }\n\n return this.#client\n }\n\n get evaluatorModel(): EvaluatorModel {\n return getTestMetadata().evaluatorModel ?? 'openai__gpt-4o-mini-2024-07-18'\n }\n\n get scenario() {\n return getTestMetadata().scenario\n }\n\n get isVaiTest() {\n return getTestMetadata().isVaiTest\n }\n\n setClient(cognitive: Client) {\n this.#client = cognitive\n }\n\n swallowErrors() {\n if (!getCurrentTest()) {\n throw new Error('cancelBail is a Vitest hook and must be called within a test')\n }\n\n this.#wrapError = true\n onTestFinished(() => {\n this.#wrapError = false\n })\n }\n}\n\nexport const Context = new VaiContext()\n","import { Assertion, expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Context } from '../context'\nimport { Output } from './predictJson'\n\nexport class AsyncExpectError<T> extends Error {\n constructor(message: string, public readonly output: Output<T>) {\n super(message)\n this.name = 'AsyncExpectError'\n }\n}\n\nconst getErrorMessages = (e: unknown): string => {\n if (e instanceof Error) {\n return e.message\n } else if (typeof e === 'string') {\n return e\n } else if (typeof e === 'object' && e !== null) {\n return JSON.stringify(e)\n }\n\n return `Unknown error: ${e}`\n}\n\nexport const asyncExpect = <T>(output: Promise<Output<T>>, assertion: (assert: Assertion<T>) => void) => {\n const promise = output.then((x) => {\n try {\n assertion(expect(x.result, x.reason))\n } catch (e: unknown) {\n if (Context.wrapError) {\n return new AsyncExpectError<T>(getErrorMessages(e), x)\n }\n throw e\n }\n return x\n })\n getCurrentTest()!.promises ??= []\n getCurrentTest()!.promises!.push(promise)\n return promise\n}\n","import { z, type ZodSchema } from '@botpress/sdk'\nimport JSON5 from 'json5'\nimport { Context } from '../context'\nimport { llm } from '../sdk-interfaces/llm/generateContent'\n\nconst nonEmptyString = z.string().trim().min(1)\nconst nonEmptyObject = z\n .object({})\n .passthrough()\n .refine((value) => Object.keys(value).length > 0, {\n message: 'Expected a non-empty object'\n })\n\nexport type Input = z.infer<typeof Input>\nconst Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()))\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Output<T = any> = z.infer<typeof Output> & { result: T }\nconst Output = z.object({\n reason: nonEmptyString.describe('A human-readable explanation of the result'),\n result: z\n .any()\n .describe(\n 'Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above'\n )\n})\n\ntype Example = z.infer<typeof Example>\nconst Example = z.object({\n input: Input,\n output: Output\n})\n\ntype InputOptions<T extends ZodSchema = ZodSchema> = z.input<typeof Options> & { outputSchema: T }\ntype Options = z.infer<typeof Options>\nconst Options = z.object({\n systemMessage: z.string(),\n examples: z.array(Example).default([]),\n input: Input,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema: z.custom<ZodSchema<any>>((value) => typeof value === 'object' && value !== null && '_def' in value),\n model: z.string()\n})\n\ntype Message = {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\nconst isValidExample =\n (outputSchema: ZodSchema) =>\n (example: Example): example is Example =>\n Input.safeParse(example.input).success &&\n Output.safeParse(example.output).success &&\n outputSchema.safeParse(example.output.result).success\n\nexport async function predictJson<T extends ZodSchema>(_options: InputOptions<T>): Promise<Output<z.infer<T>>> {\n const options = Options.parse(_options)\n const [integration, model] = options.model.split('__')\n\n if (!model?.length) {\n throw new Error('Invalid model')\n }\n\n const exampleMessages = options.examples\n .filter(isValidExample(options.outputSchema))\n .flatMap(({ input, output }) => [\n { role: 'user', content: JSON.stringify(input, null, 2) } satisfies Message,\n { role: 'assistant', content: JSON.stringify(output, null, 2) } satisfies Message\n ])\n\n const outputSchema = Output.extend({\n result: options.outputSchema.describe(Output.shape.result.description!)\n })\n\n const result = await Context.client.callAction({\n type: `${integration}:generateContent`,\n input: {\n systemPrompt: `\n${options.systemMessage}\n\n---\nPlease generate a JSON response with the following format:\n\\`\\`\\`typescript\n${await outputSchema.toTypescriptAsync()}\n\\`\\`\\`\n`.trim(),\n messages: [\n ...exampleMessages,\n {\n role: 'user',\n content: JSON.stringify(options.input, null, 2)\n }\n ],\n temperature: 0,\n responseFormat: 'json_object',\n model: { id: model! }\n } satisfies llm.generateContent.Input\n })\n\n const output = result.output as llm.generateContent.Output\n\n if (!output.choices.length || typeof output.choices?.[0]?.content !== 'string') {\n throw new Error('Invalid response from the model')\n }\n\n const json = output.choices[0].content.trim()\n\n if (!json.length) {\n throw new Error('No response from the model')\n }\n\n return outputSchema.parse(JSON5.parse(json)) as Output<z.infer<T>>\n}\n","import json5 from 'json5'\nimport { expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\n\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Output } from '../utils/predictJson'\n\nexport type ExtendedPromise<T> = PromiseLike<Output<T>> & {\n value: PromiseLike<T>\n}\n\nexport const toAssertion = <T>(promise: Promise<Output<T>>): ExtendedPromise<T> => {\n return {\n then: promise.then.bind(promise),\n value: promise.then((value) => value.result)\n }\n}\n\nexport const makeToMatchInlineSnapshot =\n <T>(promise: Promise<Output<T>>) =>\n async (expected?: string) => {\n const stack = new Error().stack!.split('\\n')[2]\n const newStack = `\nat __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)\nat randomLine (node:internal/process/task_queues:1:1)\n${stack}\n`.trim()\n\n const obj = json5.parse(expected ?? '\"\"')\n const expectation = asyncExpect(promise, (expect) => expect.toMatchObject(obj)).catch(() => {\n // we swallow the error here, as we're going to throw a new one with the correct stack\n // this is just to make vitest happy and show a nice error message\n })\n\n try {\n expect((await promise).result).toMatchObject(obj)\n } catch (err) {\n const newError = new Error()\n newError.stack = newStack\n\n expect.getState().snapshotState.match({\n isInline: true,\n received: (await promise).result,\n testName: getCurrentTest()!.name,\n error: newError,\n inlineSnapshot: expected\n })\n }\n\n return expectation\n }\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type ExtractOptions<T, S> = {\n description?: string\n examples?: { value: T; extracted: S; reason: string }[]\n}\n\nexport function extract<T extends Input, S extends z.AnyZodObject>(\n value: T,\n shape: S,\n options?: ExtractOptions<T, z.infer<S>>\n) {\n const additionalMessage = options?.description\n ? `\\nIn order to extract the right information, follow these instructions:\\n${options.description}\\n`\n : ''\n const promise = predictJson({\n systemMessage:\n 'From the given input, extract the required information into the requested format.' + additionalMessage.trim(),\n examples: options?.examples?.map(({ value, reason, extracted }) => ({\n input: value,\n output: { reason, result: extracted }\n })),\n outputSchema: shape,\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: z.infer<S>) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchObject: (expected: Partial<z.infer<S>>) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type FilterOptions<T> = {\n examples?: { value: T; reason: string; keep: boolean }[]\n}\n\nexport function filter<U>(values: U[], condition: string, options?: FilterOptions<U>) {\n const mappedValues = values.map((_, idx) =>\n z.object({\n index: z.literal(idx),\n reason: z.string(),\n keep: z.boolean()\n })\n )\n\n const input = values.map((value, idx) => ({\n index: idx,\n value\n }))\n\n const schema = z\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .tuple(mappedValues as any)\n .describe(\n 'An array of the objects with the index and a boolean value indicating if the object should be kept or not'\n )\n\n const promise = predictJson({\n systemMessage: `\nBased on the following qualification criteria, you need to filter the given list of objects.\nCiteria: ${condition}\n\n---\nYou need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.\n`.trim(),\n examples: options?.examples\n ? [\n {\n input: options?.examples?.map((v, index) => ({\n index,\n value: v.value\n })),\n output: {\n reason: 'Here are some examples',\n result: options?.examples?.map((v, idx) => ({\n index: idx,\n reason: v.reason,\n keep: v.keep\n }))\n }\n }\n ]\n : undefined,\n outputSchema: schema,\n model: Context.evaluatorModel,\n input\n }).then((x) => {\n const results = schema.parse(x.result) as { index: number; keep: boolean }[]\n return {\n result: values.filter((_, idx) => results.find((r) => r.index === idx)?.keep),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: U[]) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toHaveNoneFiltered: () => asyncExpect(promise, (expect) => expect.toEqual(values)),\n toHaveSomeFiltered: () => asyncExpect(promise, (expect) => expect.not.toEqual(values)),\n toBeEmpty: () => asyncExpect(promise, (expect) => expect.toHaveLength(0)),\n length: {\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toHaveLength(expected)),\n toBeGreaterThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.greaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.lessThanOrEqual(expected)),\n toBeBetween: (min: number, max: number) => asyncExpect(promise, (expect) => expect.length.within(min, max))\n }\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type RatingScore = 1 | 2 | 3 | 4 | 5\nexport type RateOptions<T> = {\n examples?: { value: T; rating: number; reason: string }[]\n}\n\nexport function rate<T extends Input>(value: T, condition: string, options?: RateOptions<T>) {\n const schema = z.number().min(1).max(5).describe('Rating score, higher is better (1 is the worst, 5 is the best)')\n const promise = predictJson({\n systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.\\nScoring: 1 is the worst score, 5 is the best score possible.\\nCriteria: ${condition}`,\n examples: options?.examples?.map(({ value, reason, rating }) => ({\n input: value,\n output: { reason, result: rating }\n })),\n outputSchema: schema,\n model: Context.evaluatorModel,\n input: value\n }).then((x) => {\n return {\n result: typeof x.result === 'number' ? x.result : parseInt(x.result, 10),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toBeGreaterThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeGreaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeLessThanOrEqual(expected))\n }\n}\n","import { getCurrentTest } from 'vitest/suite'\nimport { EvaluatorModel, TestMetadata } from '../context'\n\nexport const setEvaluator = (model: EvaluatorModel) => {\n const test = getCurrentTest()\n\n if (!test) {\n throw new Error('setEvaluator is a Vitest hook and must be called within a test')\n }\n\n const meta = test.meta as TestMetadata\n meta.evaluatorModel = model\n}\n","import { Client } from '@botpress/client'\nimport { Context } from '../context'\n\nexport const setupClient = (client: Client) => {\n Context.setClient(client)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAElB,mBAAqD;;;ACF9C,IAAM,YAAN,MAAM,UAAY;AAAA,EAKvB,cAAc;AACZ,SAAK,UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AACjD,WAAK,WAAW;AAChB,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,OAAiC;AACvC,SAAK,SAAS,KAAK;AAAA,EACrB;AAAA,EAEA,OAAO,QAAwB;AAC7B,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAnByB;AAAlB,IAAM,WAAN;;;ADMP,IAAM,aAAa,aAChB,OAAO,EACP,KAAK,EACL,IAAI,GAAG,oCAAoC,EAC3C,IAAI,IAAI,8BAA8B;AAGzC,IAAM,eAAe,aAAE,MAAM;AAAA,EAC3B;AAAA,EACA,aAAE,OAAO,EAAE,MAAM,WAAW,CAAC,EAAE,YAAY;AAAA,EAC3C,aAAE,OAAO,EAAE,IAAI,W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,SAAS,gEAAgE;AACjH,QAAM,UAAU,YAAY;AAAA,IAC1B,eAAe;AAAA;AAAA,YAAwL,SAAS;AAAA,IAChN,WAAU,wCAAS,aAAT,mBAAmB,IAAI,CAAC,EAAE,OAAAC,QAAO,QAAQ,OAAO,OAAO;AAAA,MAC/D,OAAOA;AAAA,MACP,QAAQ,EAAE,QAAQ,QAAQ,OAAO;AAAA,IACnC;AAAA,IACA,cAAc;AAAA,IACd,OAAO,QAAQ;AAAA,IACf,OAAO;AAAA,EACT,CAAC,EAAE,KAAK,CAAC,MAAM;AACb,WAAO;AAAA,MACL,QAAQ,OAAO,EAAE,WAAW,WAAW,EAAE,SAAS,SAAS,EAAE,QAAQ,EAAE;AAAA,MACvE,QAAQ,EAAE;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO,iCACF,YAAY,OAAO,IADjB;AAAA,IAEL,MAAM,wBAAC,aAAqB,YAAY,SAAS,CAACC,YAAWA,QAAO,QAAQ,QAAQ,CAAC,GAA/E;AAAA,IACN,uBAAuB,0BAA0B,OAAO;AAAA,IACxD,wBAAwB,wBAAC,aACvB,YAAY,SAAS,CAACA,YAAWA,QAAO,uBAAuB,QAAQ,CAAC,GADlD;AAAA,IAExB,qBAAqB,wBAAC,aACpB,YAAY,SAAS,CAACA,YAAWA,QAAO,oBAAoB,QAAQ,CAAC,GADlD;AAAA,EAEvB;AACF;AA3BgB;;;ACZhB,IAAAC,gBAA+B;AAGxB,IAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,WAAO,8BAAe;AAE5B,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,gEAAgE;AAAA,EAClF;AAEA,QAAM,OAAO,KAAK;AAClB,OAAK,iBAAiB;AACxB,GAT4B;;;ACArB,IAAM,cAAc,wBAAC,WAAmB;AAC7C,UAAQ,UAAU,MAAM;AAC1B,GAF2B;","names":["fn","import_sdk","import_suite","import_vitest","import_suite","import_sdk","output","JSON5","import_json5","import_vitest","import_suite","json5","expect","value","expect","value","expect","import_sdk","_a","expect","import_sdk","value","expect","import_suite"]}
|
package/dist/index.js
CHANGED
|
@@ -348,12 +348,12 @@ ${options.description}
|
|
|
348
348
|
__name(extract, "extract");
|
|
349
349
|
|
|
350
350
|
// src/assertions/filter.ts
|
|
351
|
-
import {
|
|
351
|
+
import { z as z4 } from "@botpress/sdk";
|
|
352
352
|
function filter(values, condition, options) {
|
|
353
353
|
var _a, _b;
|
|
354
354
|
const mappedValues = values.map(
|
|
355
355
|
(_, idx) => z4.object({
|
|
356
|
-
index: literal(idx),
|
|
356
|
+
index: z4.literal(idx),
|
|
357
357
|
reason: z4.string(),
|
|
358
358
|
keep: z4.boolean()
|
|
359
359
|
})
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/task/compare.ts","../src/utils/deferred.ts","../src/assertions/check.ts","../src/context.ts","../src/utils/asyncAssertion.ts","../src/utils/predictJson.ts","../src/assertions/extension.ts","../src/assertions/extract.ts","../src/assertions/filter.ts","../src/assertions/rate.ts","../src/hooks/setEvaluator.ts","../src/hooks/setupClient.ts"],"sourcesContent":["import { z } from '@botpress/sdk'\nimport { TestFunction } from 'vitest'\nimport { createTaskCollector, getCurrentSuite } from 'vitest/suite'\nimport { TestMetadata } from '../context'\nimport { Deferred } from '../utils/deferred'\n\nconst scenarioId = z\n .string()\n .trim()\n .min(1, 'Scenario ID/name must not be empty')\n .max(50, 'Scenario ID/name is too long')\n\nexport type ScenarioLike = z.infer<typeof ScenarioLike>\nconst ScenarioLike = z.union([\n scenarioId,\n z.object({ name: scenarioId }).passthrough(),\n z.object({ id: scenarioId }).passthrough()\n])\n\nconst getScenarioName = (scenario: ScenarioLike) =>\n (typeof scenario === 'string' ? scenario : 'name' in scenario ? scenario?.name : scenario?.id) as string\n\nconst scenarioArgs = z\n .array(ScenarioLike)\n .min(2, 'You need at least two scenarios to compare')\n .max(10, 'You can only compare up to 10 scenarios')\n .refine((scenarios) => {\n const set = new Set<string>()\n scenarios.forEach((scenario) => set.add(getScenarioName(scenario)))\n return set.size === scenarios.length\n }, 'Scenarios names must be unique')\n\nexport function compare<T extends ReadonlyArray<ScenarioLike>>(\n name: string | Function,\n scenarios: T,\n fn?: TestFunction<{\n scenario: T[number]\n }>\n) {\n scenarios = scenarioArgs.parse(scenarios) as unknown as T\n\n return createTaskCollector((_name, fn, timeout) => {\n const currentSuite = getCurrentSuite()\n\n let completedCount = 0\n const finished = new Deferred<void>()\n\n for (const scenario of scenarios) {\n const key = getScenarioName(scenario)\n\n currentSuite.task(key, {\n meta: {\n scenario: key,\n isVaiTest: true\n } satisfies TestMetadata,\n handler: async (context) => {\n const extendedContext = Object.freeze({\n scenario\n })\n context.onTestFinished(() => {\n if (++completedCount === scenarios.length) {\n finished.resolve()\n }\n })\n\n await fn({ ...context, ...extendedContext })\n },\n timeout: timeout ?? 10_000\n })\n }\n })(name, fn)\n}\n","export class Deferred<T> {\n promise: Promise<T>\n private _resolve!: (value: T | PromiseLike<T>) => void\n private _reject!: (reason?: unknown) => void\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve\n this._reject = reject\n })\n }\n\n resolve(value: T | PromiseLike<T>): void {\n this._resolve(value)\n }\n\n reject(reason?: unknown): void {\n this._reject(reason)\n }\n}\n","import { z } from '@botpress/sdk'\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type CheckOptions<T> = {\n examples?: { value: T; expected: boolean; reason: string }[]\n}\n\nexport function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>) {\n const promise = predictJson({\n systemMessage: `Check that the value meets the condition: ${condition}`,\n examples: options?.examples?.map(({ value, reason, expected }) => ({\n input: value,\n output: { reason, result: expected }\n })),\n outputSchema: z.boolean(),\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: boolean) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import type { Client } from '@botpress/client'\nimport { onTestFinished } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Models } from './models'\n\nexport type EvaluatorModel = (typeof Models)[number]['id']\n\nexport type TestMetadata = {\n isVaiTest: boolean\n scenario?: string\n evaluatorModel?: EvaluatorModel\n}\n\nconst getTestMetadata = (): TestMetadata => {\n const test = getCurrentTest()\n return (test?.meta ?? {\n isVaiTest: false\n }) as TestMetadata\n}\n\nclass VaiContext {\n #client: Client | null = null\n #wrapError = false\n\n get wrapError() {\n return this.#wrapError\n }\n\n get client() {\n if (!this.#client) {\n throw new Error('Botpress client is not set')\n }\n\n return this.#client\n }\n\n get evaluatorModel(): EvaluatorModel {\n return getTestMetadata().evaluatorModel ?? 'openai__gpt-4o-mini-2024-07-18'\n }\n\n get scenario() {\n return getTestMetadata().scenario\n }\n\n get isVaiTest() {\n return getTestMetadata().isVaiTest\n }\n\n setClient(cognitive: Client) {\n this.#client = cognitive\n }\n\n swallowErrors() {\n if (!getCurrentTest()) {\n throw new Error('cancelBail is a Vitest hook and must be called within a test')\n }\n\n this.#wrapError = true\n onTestFinished(() => {\n this.#wrapError = false\n })\n }\n}\n\nexport const Context = new VaiContext()\n","import { Assertion, expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Context } from '../context'\nimport { Output } from './predictJson'\n\nexport class AsyncExpectError<T> extends Error {\n constructor(message: string, public readonly output: Output<T>) {\n super(message)\n this.name = 'AsyncExpectError'\n }\n}\n\nconst getErrorMessages = (e: unknown): string => {\n if (e instanceof Error) {\n return e.message\n } else if (typeof e === 'string') {\n return e\n } else if (typeof e === 'object' && e !== null) {\n return JSON.stringify(e)\n }\n\n return `Unknown error: ${e}`\n}\n\nexport const asyncExpect = <T>(output: Promise<Output<T>>, assertion: (assert: Assertion<T>) => void) => {\n const promise = output.then((x) => {\n try {\n assertion(expect(x.result, x.reason))\n } catch (e: unknown) {\n if (Context.wrapError) {\n return new AsyncExpectError<T>(getErrorMessages(e), x)\n }\n throw e\n }\n return x\n })\n getCurrentTest()!.promises ??= []\n getCurrentTest()!.promises!.push(promise)\n return promise\n}\n","import { z, type ZodSchema } from '@botpress/sdk'\nimport JSON5 from 'json5'\nimport { Context } from '../context'\nimport { llm } from '../sdk-interfaces/llm/generateContent'\n\nconst nonEmptyString = z.string().trim().min(1)\nconst nonEmptyObject = z\n .object({})\n .passthrough()\n .refine((value) => Object.keys(value).length > 0, {\n message: 'Expected a non-empty object'\n })\n\nexport type Input = z.infer<typeof Input>\nconst Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()))\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Output<T = any> = z.infer<typeof Output> & { result: T }\nconst Output = z.object({\n reason: nonEmptyString.describe('A human-readable explanation of the result'),\n result: z\n .any()\n .describe(\n 'Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above'\n )\n})\n\ntype Example = z.infer<typeof Example>\nconst Example = z.object({\n input: Input,\n output: Output\n})\n\ntype InputOptions<T extends ZodSchema = ZodSchema> = z.input<typeof Options> & { outputSchema: T }\ntype Options = z.infer<typeof Options>\nconst Options = z.object({\n systemMessage: z.string(),\n examples: z.array(Example).default([]),\n input: Input,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema: z.custom<ZodSchema<any>>((value) => typeof value === 'object' && value !== null && '_def' in value),\n model: z.string()\n})\n\ntype Message = {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\nconst isValidExample =\n (outputSchema: ZodSchema) =>\n (example: Example): example is Example =>\n Input.safeParse(example.input).success &&\n Output.safeParse(example.output).success &&\n outputSchema.safeParse(example.output.result).success\n\nexport async function predictJson<T extends ZodSchema>(_options: InputOptions<T>): Promise<Output<z.infer<T>>> {\n const options = Options.parse(_options)\n const [integration, model] = options.model.split('__')\n\n if (!model?.length) {\n throw new Error('Invalid model')\n }\n\n const exampleMessages = options.examples\n .filter(isValidExample(options.outputSchema))\n .flatMap(({ input, output }) => [\n { role: 'user', content: JSON.stringify(input, null, 2) } satisfies Message,\n { role: 'assistant', content: JSON.stringify(output, null, 2) } satisfies Message\n ])\n\n const outputSchema = Output.extend({\n result: options.outputSchema.describe(Output.shape.result.description!)\n })\n\n const result = await Context.client.callAction({\n type: `${integration}:generateContent`,\n input: {\n systemPrompt: `\n${options.systemMessage}\n\n---\nPlease generate a JSON response with the following format:\n\\`\\`\\`typescript\n${await outputSchema.toTypescriptAsync()}\n\\`\\`\\`\n`.trim(),\n messages: [\n ...exampleMessages,\n {\n role: 'user',\n content: JSON.stringify(options.input, null, 2)\n }\n ],\n temperature: 0,\n responseFormat: 'json_object',\n model: { id: model! }\n } satisfies llm.generateContent.Input\n })\n\n const output = result.output as llm.generateContent.Output\n\n if (!output.choices.length || typeof output.choices?.[0]?.content !== 'string') {\n throw new Error('Invalid response from the model')\n }\n\n const json = output.choices[0].content.trim()\n\n if (!json.length) {\n throw new Error('No response from the model')\n }\n\n return outputSchema.parse(JSON5.parse(json)) as Output<z.infer<T>>\n}\n","import json5 from 'json5'\nimport { expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\n\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Output } from '../utils/predictJson'\n\nexport type ExtendedPromise<T> = PromiseLike<Output<T>> & {\n value: PromiseLike<T>\n}\n\nexport const toAssertion = <T>(promise: Promise<Output<T>>): ExtendedPromise<T> => {\n return {\n then: promise.then.bind(promise),\n value: promise.then((value) => value.result)\n }\n}\n\nexport const makeToMatchInlineSnapshot =\n <T>(promise: Promise<Output<T>>) =>\n async (expected?: string) => {\n const stack = new Error().stack!.split('\\n')[2]\n const newStack = `\nat __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)\nat randomLine (node:internal/process/task_queues:1:1)\n${stack}\n`.trim()\n\n const obj = json5.parse(expected ?? '\"\"')\n const expectation = asyncExpect(promise, (expect) => expect.toMatchObject(obj)).catch(() => {\n // we swallow the error here, as we're going to throw a new one with the correct stack\n // this is just to make vitest happy and show a nice error message\n })\n\n try {\n expect((await promise).result).toMatchObject(obj)\n } catch (err) {\n const newError = new Error()\n newError.stack = newStack\n\n expect.getState().snapshotState.match({\n isInline: true,\n received: (await promise).result,\n testName: getCurrentTest()!.name,\n error: newError,\n inlineSnapshot: expected\n })\n }\n\n return expectation\n }\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type ExtractOptions<T, S> = {\n description?: string\n examples?: { value: T; extracted: S; reason: string }[]\n}\n\nexport function extract<T extends Input, S extends z.AnyZodObject>(\n value: T,\n shape: S,\n options?: ExtractOptions<T, z.infer<S>>\n) {\n const additionalMessage = options?.description\n ? `\\nIn order to extract the right information, follow these instructions:\\n${options.description}\\n`\n : ''\n const promise = predictJson({\n systemMessage:\n 'From the given input, extract the required information into the requested format.' + additionalMessage.trim(),\n examples: options?.examples?.map(({ value, reason, extracted }) => ({\n input: value,\n output: { reason, result: extracted }\n })),\n outputSchema: shape,\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: z.infer<S>) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchObject: (expected: Partial<z.infer<S>>) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { literal, z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type FilterOptions<T> = {\n examples?: { value: T; reason: string; keep: boolean }[]\n}\n\nexport function filter<U>(values: U[], condition: string, options?: FilterOptions<U>) {\n const mappedValues = values.map((_, idx) =>\n z.object({\n index: literal(idx),\n reason: z.string(),\n keep: z.boolean()\n })\n )\n\n const input = values.map((value, idx) => ({\n index: idx,\n value\n }))\n\n const schema = z\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .tuple(mappedValues as any)\n .describe(\n 'An array of the objects with the index and a boolean value indicating if the object should be kept or not'\n )\n\n const promise = predictJson({\n systemMessage: `\nBased on the following qualification criteria, you need to filter the given list of objects.\nCiteria: ${condition}\n\n---\nYou need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.\n`.trim(),\n examples: options?.examples\n ? [\n {\n input: options?.examples?.map((v, index) => ({\n index,\n value: v.value\n })),\n output: {\n reason: 'Here are some examples',\n result: options?.examples?.map((v, idx) => ({\n index: idx,\n reason: v.reason,\n keep: v.keep\n }))\n }\n }\n ]\n : undefined,\n outputSchema: schema,\n model: Context.evaluatorModel,\n input\n }).then((x) => {\n const results = schema.parse(x.result) as { index: number; keep: boolean }[]\n return {\n result: values.filter((_, idx) => results.find((r) => r.index === idx)?.keep),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: U[]) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toHaveNoneFiltered: () => asyncExpect(promise, (expect) => expect.toEqual(values)),\n toHaveSomeFiltered: () => asyncExpect(promise, (expect) => expect.not.toEqual(values)),\n toBeEmpty: () => asyncExpect(promise, (expect) => expect.toHaveLength(0)),\n length: {\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toHaveLength(expected)),\n toBeGreaterThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.greaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.lessThanOrEqual(expected)),\n toBeBetween: (min: number, max: number) => asyncExpect(promise, (expect) => expect.length.within(min, max))\n }\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type RatingScore = 1 | 2 | 3 | 4 | 5\nexport type RateOptions<T> = {\n examples?: { value: T; rating: number; reason: string }[]\n}\n\nexport function rate<T extends Input>(value: T, condition: string, options?: RateOptions<T>) {\n const schema = z.number().min(1).max(5).describe('Rating score, higher is better (1 is the worst, 5 is the best)')\n const promise = predictJson({\n systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.\\nScoring: 1 is the worst score, 5 is the best score possible.\\nCriteria: ${condition}`,\n examples: options?.examples?.map(({ value, reason, rating }) => ({\n input: value,\n output: { reason, result: rating }\n })),\n outputSchema: schema,\n model: Context.evaluatorModel,\n input: value\n }).then((x) => {\n return {\n result: typeof x.result === 'number' ? x.result : parseInt(x.result, 10),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toBeGreaterThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeGreaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeLessThanOrEqual(expected))\n }\n}\n","import { getCurrentTest } from 'vitest/suite'\nimport { EvaluatorModel, TestMetadata } from '../context'\n\nexport const setEvaluator = (model: EvaluatorModel) => {\n const test = getCurrentTest()\n\n if (!test) {\n throw new Error('setEvaluator is a Vitest hook and must be called within a test')\n }\n\n const meta = test.meta as TestMetadata\n meta.evaluatorModel = model\n}\n","import { Client } from '@botpress/client'\nimport { Context } from '../context'\n\nexport const setupClient = (client: Client) => {\n Context.setClient(client)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS;AAElB,SAAS,qBAAqB,uBAAuB;;;ACF9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C,GAA/E;AAAA,IACN,uBAAuB,0BAA0B,OAAO;AAAA,IACxD,wBAAwB,wBAAC,aACvB,YAAY,SAAS,CAACA,YAAWA,QAAO,uBAAuB,QAAQ,CAAC,GADlD;AAAA,IAExB,qBAAqB,wBAAC,aACpB,YAAY,SAAS,CAACA,YAAWA,QAAO,oBAAoB,QAAQ,CAAC,GADlD;AAAA,EAEvB;AACF;AA3BgB;;;ACZhB,SAAS,kBAAAC,uBAAsB;AAGxB,IAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,OAAOC,gBAAe;AAE5B,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,gEAAgE;AAAA,EAClF;AAEA,QAAM,OAAO,KAAK;AAClB,OAAK,iBAAiB;AACxB,GAT4B;;;ACArB,IAAM,cAAc,wBAAC,WAAmB;AAC7C,UAAQ,UAAU,MAAM;AAC1B,GAF2B;","names":["fn","z","getCurrentTest","getCurrentTest","z","z","output","expect","getCurrentTest","expect","getCurrentTest","value","z","expect","value","expect","z","z","_a","expect","z","z","value","expect","getCurrentTest","getCurrentTest"]}
|
|
1
|
+
{"version":3,"sources":["../src/task/compare.ts","../src/utils/deferred.ts","../src/assertions/check.ts","../src/context.ts","../src/utils/asyncAssertion.ts","../src/utils/predictJson.ts","../src/assertions/extension.ts","../src/assertions/extract.ts","../src/assertions/filter.ts","../src/assertions/rate.ts","../src/hooks/setEvaluator.ts","../src/hooks/setupClient.ts"],"sourcesContent":["import { z } from '@botpress/sdk'\nimport { TestFunction } from 'vitest'\nimport { createTaskCollector, getCurrentSuite } from 'vitest/suite'\nimport { TestMetadata } from '../context'\nimport { Deferred } from '../utils/deferred'\n\nconst scenarioId = z\n .string()\n .trim()\n .min(1, 'Scenario ID/name must not be empty')\n .max(50, 'Scenario ID/name is too long')\n\nexport type ScenarioLike = z.infer<typeof ScenarioLike>\nconst ScenarioLike = z.union([\n scenarioId,\n z.object({ name: scenarioId }).passthrough(),\n z.object({ id: scenarioId }).passthrough()\n])\n\nconst getScenarioName = (scenario: ScenarioLike) =>\n (typeof scenario === 'string' ? scenario : 'name' in scenario ? scenario?.name : scenario?.id) as string\n\nconst scenarioArgs = z\n .array(ScenarioLike)\n .min(2, 'You need at least two scenarios to compare')\n .max(10, 'You can only compare up to 10 scenarios')\n .refine((scenarios) => {\n const set = new Set<string>()\n scenarios.forEach((scenario) => set.add(getScenarioName(scenario)))\n return set.size === scenarios.length\n }, 'Scenarios names must be unique')\n\nexport function compare<T extends ReadonlyArray<ScenarioLike>>(\n name: string | Function,\n scenarios: T,\n fn?: TestFunction<{\n scenario: T[number]\n }>\n) {\n scenarios = scenarioArgs.parse(scenarios) as unknown as T\n\n return createTaskCollector((_name, fn, timeout) => {\n const currentSuite = getCurrentSuite()\n\n let completedCount = 0\n const finished = new Deferred<void>()\n\n for (const scenario of scenarios) {\n const key = getScenarioName(scenario)\n\n currentSuite.task(key, {\n meta: {\n scenario: key,\n isVaiTest: true\n } satisfies TestMetadata,\n handler: async (context) => {\n const extendedContext = Object.freeze({\n scenario\n })\n context.onTestFinished(() => {\n if (++completedCount === scenarios.length) {\n finished.resolve()\n }\n })\n\n await fn({ ...context, ...extendedContext })\n },\n timeout: timeout ?? 10_000\n })\n }\n })(name, fn)\n}\n","export class Deferred<T> {\n promise: Promise<T>\n private _resolve!: (value: T | PromiseLike<T>) => void\n private _reject!: (reason?: unknown) => void\n\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve\n this._reject = reject\n })\n }\n\n resolve(value: T | PromiseLike<T>): void {\n this._resolve(value)\n }\n\n reject(reason?: unknown): void {\n this._reject(reason)\n }\n}\n","import { z } from '@botpress/sdk'\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type CheckOptions<T> = {\n examples?: { value: T; expected: boolean; reason: string }[]\n}\n\nexport function check<T extends Input>(value: T, condition: string, options?: CheckOptions<T>) {\n const promise = predictJson({\n systemMessage: `Check that the value meets the condition: ${condition}`,\n examples: options?.examples?.map(({ value, reason, expected }) => ({\n input: value,\n output: { reason, result: expected }\n })),\n outputSchema: z.boolean(),\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: boolean) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import type { Client } from '@botpress/client'\nimport { onTestFinished } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Models } from './models'\n\nexport type EvaluatorModel = (typeof Models)[number]['id']\n\nexport type TestMetadata = {\n isVaiTest: boolean\n scenario?: string\n evaluatorModel?: EvaluatorModel\n}\n\nconst getTestMetadata = (): TestMetadata => {\n const test = getCurrentTest()\n return (test?.meta ?? {\n isVaiTest: false\n }) as TestMetadata\n}\n\nclass VaiContext {\n #client: Client | null = null\n #wrapError = false\n\n get wrapError() {\n return this.#wrapError\n }\n\n get client() {\n if (!this.#client) {\n throw new Error('Botpress client is not set')\n }\n\n return this.#client\n }\n\n get evaluatorModel(): EvaluatorModel {\n return getTestMetadata().evaluatorModel ?? 'openai__gpt-4o-mini-2024-07-18'\n }\n\n get scenario() {\n return getTestMetadata().scenario\n }\n\n get isVaiTest() {\n return getTestMetadata().isVaiTest\n }\n\n setClient(cognitive: Client) {\n this.#client = cognitive\n }\n\n swallowErrors() {\n if (!getCurrentTest()) {\n throw new Error('cancelBail is a Vitest hook and must be called within a test')\n }\n\n this.#wrapError = true\n onTestFinished(() => {\n this.#wrapError = false\n })\n }\n}\n\nexport const Context = new VaiContext()\n","import { Assertion, expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\nimport { Context } from '../context'\nimport { Output } from './predictJson'\n\nexport class AsyncExpectError<T> extends Error {\n constructor(message: string, public readonly output: Output<T>) {\n super(message)\n this.name = 'AsyncExpectError'\n }\n}\n\nconst getErrorMessages = (e: unknown): string => {\n if (e instanceof Error) {\n return e.message\n } else if (typeof e === 'string') {\n return e\n } else if (typeof e === 'object' && e !== null) {\n return JSON.stringify(e)\n }\n\n return `Unknown error: ${e}`\n}\n\nexport const asyncExpect = <T>(output: Promise<Output<T>>, assertion: (assert: Assertion<T>) => void) => {\n const promise = output.then((x) => {\n try {\n assertion(expect(x.result, x.reason))\n } catch (e: unknown) {\n if (Context.wrapError) {\n return new AsyncExpectError<T>(getErrorMessages(e), x)\n }\n throw e\n }\n return x\n })\n getCurrentTest()!.promises ??= []\n getCurrentTest()!.promises!.push(promise)\n return promise\n}\n","import { z, type ZodSchema } from '@botpress/sdk'\nimport JSON5 from 'json5'\nimport { Context } from '../context'\nimport { llm } from '../sdk-interfaces/llm/generateContent'\n\nconst nonEmptyString = z.string().trim().min(1)\nconst nonEmptyObject = z\n .object({})\n .passthrough()\n .refine((value) => Object.keys(value).length > 0, {\n message: 'Expected a non-empty object'\n })\n\nexport type Input = z.infer<typeof Input>\nconst Input = nonEmptyString.or(nonEmptyObject).or(z.array(z.any()))\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Output<T = any> = z.infer<typeof Output> & { result: T }\nconst Output = z.object({\n reason: nonEmptyString.describe('A human-readable explanation of the result'),\n result: z\n .any()\n .describe(\n 'Your best guess at the output according to the instructions provided, rooted in the context of the input and the reason above'\n )\n})\n\ntype Example = z.infer<typeof Example>\nconst Example = z.object({\n input: Input,\n output: Output\n})\n\ntype InputOptions<T extends ZodSchema = ZodSchema> = z.input<typeof Options> & { outputSchema: T }\ntype Options = z.infer<typeof Options>\nconst Options = z.object({\n systemMessage: z.string(),\n examples: z.array(Example).default([]),\n input: Input,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n outputSchema: z.custom<ZodSchema<any>>((value) => typeof value === 'object' && value !== null && '_def' in value),\n model: z.string()\n})\n\ntype Message = {\n role: 'user' | 'assistant' | 'system'\n content: string\n}\n\nconst isValidExample =\n (outputSchema: ZodSchema) =>\n (example: Example): example is Example =>\n Input.safeParse(example.input).success &&\n Output.safeParse(example.output).success &&\n outputSchema.safeParse(example.output.result).success\n\nexport async function predictJson<T extends ZodSchema>(_options: InputOptions<T>): Promise<Output<z.infer<T>>> {\n const options = Options.parse(_options)\n const [integration, model] = options.model.split('__')\n\n if (!model?.length) {\n throw new Error('Invalid model')\n }\n\n const exampleMessages = options.examples\n .filter(isValidExample(options.outputSchema))\n .flatMap(({ input, output }) => [\n { role: 'user', content: JSON.stringify(input, null, 2) } satisfies Message,\n { role: 'assistant', content: JSON.stringify(output, null, 2) } satisfies Message\n ])\n\n const outputSchema = Output.extend({\n result: options.outputSchema.describe(Output.shape.result.description!)\n })\n\n const result = await Context.client.callAction({\n type: `${integration}:generateContent`,\n input: {\n systemPrompt: `\n${options.systemMessage}\n\n---\nPlease generate a JSON response with the following format:\n\\`\\`\\`typescript\n${await outputSchema.toTypescriptAsync()}\n\\`\\`\\`\n`.trim(),\n messages: [\n ...exampleMessages,\n {\n role: 'user',\n content: JSON.stringify(options.input, null, 2)\n }\n ],\n temperature: 0,\n responseFormat: 'json_object',\n model: { id: model! }\n } satisfies llm.generateContent.Input\n })\n\n const output = result.output as llm.generateContent.Output\n\n if (!output.choices.length || typeof output.choices?.[0]?.content !== 'string') {\n throw new Error('Invalid response from the model')\n }\n\n const json = output.choices[0].content.trim()\n\n if (!json.length) {\n throw new Error('No response from the model')\n }\n\n return outputSchema.parse(JSON5.parse(json)) as Output<z.infer<T>>\n}\n","import json5 from 'json5'\nimport { expect } from 'vitest'\nimport { getCurrentTest } from 'vitest/suite'\n\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Output } from '../utils/predictJson'\n\nexport type ExtendedPromise<T> = PromiseLike<Output<T>> & {\n value: PromiseLike<T>\n}\n\nexport const toAssertion = <T>(promise: Promise<Output<T>>): ExtendedPromise<T> => {\n return {\n then: promise.then.bind(promise),\n value: promise.then((value) => value.result)\n }\n}\n\nexport const makeToMatchInlineSnapshot =\n <T>(promise: Promise<Output<T>>) =>\n async (expected?: string) => {\n const stack = new Error().stack!.split('\\n')[2]\n const newStack = `\nat __INLINE_SNAPSHOT__ (node:internal/process/task_queues:1:1)\nat randomLine (node:internal/process/task_queues:1:1)\n${stack}\n`.trim()\n\n const obj = json5.parse(expected ?? '\"\"')\n const expectation = asyncExpect(promise, (expect) => expect.toMatchObject(obj)).catch(() => {\n // we swallow the error here, as we're going to throw a new one with the correct stack\n // this is just to make vitest happy and show a nice error message\n })\n\n try {\n expect((await promise).result).toMatchObject(obj)\n } catch (err) {\n const newError = new Error()\n newError.stack = newStack\n\n expect.getState().snapshotState.match({\n isInline: true,\n received: (await promise).result,\n testName: getCurrentTest()!.name,\n error: newError,\n inlineSnapshot: expected\n })\n }\n\n return expectation\n }\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type ExtractOptions<T, S> = {\n description?: string\n examples?: { value: T; extracted: S; reason: string }[]\n}\n\nexport function extract<T extends Input, S extends z.AnyZodObject>(\n value: T,\n shape: S,\n options?: ExtractOptions<T, z.infer<S>>\n) {\n const additionalMessage = options?.description\n ? `\\nIn order to extract the right information, follow these instructions:\\n${options.description}\\n`\n : ''\n const promise = predictJson({\n systemMessage:\n 'From the given input, extract the required information into the requested format.' + additionalMessage.trim(),\n examples: options?.examples?.map(({ value, reason, extracted }) => ({\n input: value,\n output: { reason, result: extracted }\n })),\n outputSchema: shape,\n model: Context.evaluatorModel,\n input: value\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: z.infer<S>) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchObject: (expected: Partial<z.infer<S>>) => asyncExpect(promise, (expect) => expect.toMatchObject(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise)\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type FilterOptions<T> = {\n examples?: { value: T; reason: string; keep: boolean }[]\n}\n\nexport function filter<U>(values: U[], condition: string, options?: FilterOptions<U>) {\n const mappedValues = values.map((_, idx) =>\n z.object({\n index: z.literal(idx),\n reason: z.string(),\n keep: z.boolean()\n })\n )\n\n const input = values.map((value, idx) => ({\n index: idx,\n value\n }))\n\n const schema = z\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .tuple(mappedValues as any)\n .describe(\n 'An array of the objects with the index and a boolean value indicating if the object should be kept or not'\n )\n\n const promise = predictJson({\n systemMessage: `\nBased on the following qualification criteria, you need to filter the given list of objects.\nCiteria: ${condition}\n\n---\nYou need to return an array of objects with the index and a boolean value indicating if the object should be kept or not.\n`.trim(),\n examples: options?.examples\n ? [\n {\n input: options?.examples?.map((v, index) => ({\n index,\n value: v.value\n })),\n output: {\n reason: 'Here are some examples',\n result: options?.examples?.map((v, idx) => ({\n index: idx,\n reason: v.reason,\n keep: v.keep\n }))\n }\n }\n ]\n : undefined,\n outputSchema: schema,\n model: Context.evaluatorModel,\n input\n }).then((x) => {\n const results = schema.parse(x.result) as { index: number; keep: boolean }[]\n return {\n result: values.filter((_, idx) => results.find((r) => r.index === idx)?.keep),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: U[]) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toHaveNoneFiltered: () => asyncExpect(promise, (expect) => expect.toEqual(values)),\n toHaveSomeFiltered: () => asyncExpect(promise, (expect) => expect.not.toEqual(values)),\n toBeEmpty: () => asyncExpect(promise, (expect) => expect.toHaveLength(0)),\n length: {\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toHaveLength(expected)),\n toBeGreaterThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.greaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: number) =>\n asyncExpect(promise, (expect) => expect.length.lessThanOrEqual(expected)),\n toBeBetween: (min: number, max: number) => asyncExpect(promise, (expect) => expect.length.within(min, max))\n }\n }\n}\n","import { z } from '@botpress/sdk'\n\nimport { Context } from '../context'\nimport { asyncExpect } from '../utils/asyncAssertion'\nimport { Input, predictJson } from '../utils/predictJson'\nimport { makeToMatchInlineSnapshot, toAssertion } from './extension'\n\nexport type RatingScore = 1 | 2 | 3 | 4 | 5\nexport type RateOptions<T> = {\n examples?: { value: T; rating: number; reason: string }[]\n}\n\nexport function rate<T extends Input>(value: T, condition: string, options?: RateOptions<T>) {\n const schema = z.number().min(1).max(5).describe('Rating score, higher is better (1 is the worst, 5 is the best)')\n const promise = predictJson({\n systemMessage: `Based on the following qualification criteria, you need to rate the given situation from a score of 1 to 5.\\nScoring: 1 is the worst score, 5 is the best score possible.\\nCriteria: ${condition}`,\n examples: options?.examples?.map(({ value, reason, rating }) => ({\n input: value,\n output: { reason, result: rating }\n })),\n outputSchema: schema,\n model: Context.evaluatorModel,\n input: value\n }).then((x) => {\n return {\n result: typeof x.result === 'number' ? x.result : parseInt(x.result, 10),\n reason: x.reason\n }\n })\n\n return {\n ...toAssertion(promise),\n toBe: (expected: number) => asyncExpect(promise, (expect) => expect.toEqual(expected)),\n toMatchInlineSnapshot: makeToMatchInlineSnapshot(promise),\n toBeGreaterThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeGreaterThanOrEqual(expected)),\n toBeLessThanOrEqual: (expected: RatingScore) =>\n asyncExpect(promise, (expect) => expect.toBeLessThanOrEqual(expected))\n }\n}\n","import { getCurrentTest } from 'vitest/suite'\nimport { EvaluatorModel, TestMetadata } from '../context'\n\nexport const setEvaluator = (model: EvaluatorModel) => {\n const test = getCurrentTest()\n\n if (!test) {\n throw new Error('setEvaluator is a Vitest hook and must be called within a test')\n }\n\n const meta = test.meta as TestMetadata\n meta.evaluatorModel = model\n}\n","import { Client } from '@botpress/client'\nimport { Context } from '../context'\n\nexport const setupClient = (client: Client) => {\n Context.setClient(client)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,SAAS;AAElB,SAAS,qBAAqB,uBAAuB;;;ACF9C,IAAM,YAAN,MAAM,UAAY;AAAA,EAKvB,cAAc;AACZ,SAAK,UAAU,IAAI,QAAW,CAAC,SAAS,WAAW;AACjD,WAAK,WAAW;AAChB,WAAK,UAAU;AAAA,IACjB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,OAAiC;AACvC,SAAK,SAAS,KAAK;AAAA,EACrB;AAAA,EAEA,OAAO,QAAwB;AAC7B,SAAK,QAAQ,MAAM;AAAA,EACrB;AACF;AAnByB;AAAlB,IAAM,WAAN;;;ADMP,IAAM,aAAa,EAChB,OAAO,EACP,KAAK,EACL,IAAI,GAAG,oCAAoC,EAC3C,IAAI,IAAI,8BAA8B;AAGzC,IAAM,eAAe,EAAE,MAAM;AAAA,EAC3B;AAAA,EACA,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC,EAAE,YAAY;AAAA,EAC3C,EAAE,OAAO,EAAE,IAAI,WAAW,CAAC,EAAE,YAAY;AAC3C,CAAC;AAED,IAAM,kBAAkB,wBAAC,aACtB,OAAO,aAAa,WAAW,WAAW,UAAU,WAAW,qCAAU,OAAO,qCAAU,IADrE;AAGxB,IAAM,eAAe,EAClB,MAAM,YAAY,EAClB,IAAI,GAAG,4CAA4C,EACnD,IAAI,IAAI,yCAAyC,EACjD,OAAO,CAAC,cAAc;AACrB,QAAM,MAAM,oBAAI,IAAY;AAC5B,YAAU,QAAQ,CAAC,aAAa,IAAI,IAAI,gBAAgB,QAAQ,CAAC,CAAC;AAClE,SAAO,IAAI,SAAS,UAAU;AAChC,GAAG,gCAAgC;AAE9B,SAAS,QACd,MACA,WACA,IAGA;AACA,cAAY,aAAa,MAAM,SAAS;AAExC,SAAO,oBAAo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,SAAS,EAAE,QAAQ,EAAE;AAAA,MACvE,QAAQ,EAAE;AAAA,IACZ;AAAA,EACF,CAAC;AAED,SAAO,iCACF,YAAY,OAAO,IADjB;AAAA,IAEL,MAAM,wBAAC,aAAqB,YAAY,SAAS,CAACC,YAAWA,QAAO,QAAQ,QAAQ,CAAC,GAA/E;AAAA,IACN,uBAAuB,0BAA0B,OAAO;AAAA,IACxD,wBAAwB,wBAAC,aACvB,YAAY,SAAS,CAACA,YAAWA,QAAO,uBAAuB,QAAQ,CAAC,GADlD;AAAA,IAExB,qBAAqB,wBAAC,aACpB,YAAY,SAAS,CAACA,YAAWA,QAAO,oBAAoB,QAAQ,CAAC,GADlD;AAAA,EAEvB;AACF;AA3BgB;;;ACZhB,SAAS,kBAAAC,uBAAsB;AAGxB,IAAM,eAAe,wBAAC,UAA0B;AACrD,QAAM,OAAOC,gBAAe;AAE5B,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,gEAAgE;AAAA,EAClF;AAEA,QAAM,OAAO,KAAK;AAClB,OAAK,iBAAiB;AACxB,GAT4B;;;ACArB,IAAM,cAAc,wBAAC,WAAmB;AAC7C,UAAQ,UAAU,MAAM;AAC1B,GAF2B;","names":["fn","z","getCurrentTest","getCurrentTest","z","z","output","expect","getCurrentTest","expect","getCurrentTest","value","z","expect","value","expect","z","z","_a","expect","z","z","value","expect","getCurrentTest","getCurrentTest"]}
|