UNPKG

llama-flow

Version:

The Typescript-first prompt engineering toolkit for working with chat based LLMs.

50 lines (49 loc) 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const extracter_1 = require("./extracter"); const extracter_test_data_1 = require("./extracter.test.data"); describe('extractJSONObjectResponse', () => { for (const testObject of extracter_test_data_1.testJSONObjects) { it('Should return null when there are no JSON array', () => { expect((0, extracter_1.extractJSONObjectResponse)(`hello world! [ "val 1", "val 2" ] end`)).toBe(undefined); }); it('Should extract a JSON object response with no chars in front or behind', () => { expect((0, extracter_1.extractJSONObjectResponse)(testObject)).toEqual(testObject); }); it('Should extract when there are chars only in front', () => { expect((0, extracter_1.extractJSONObjectResponse)(`text in front ${testObject}`)).toEqual(testObject); }); it('Should extract when there are chars both in front and behind', () => { expect((0, extracter_1.extractJSONObjectResponse)(`text in front ${testObject} text behind`)).toEqual(testObject); }); it('Should extract where there are only chars behind', () => { expect((0, extracter_1.extractJSONObjectResponse)(`${testObject}more text behind`)).toEqual(testObject); }); } }); describe('extratJSONArrayResponse', () => { const testJSONArray = `["statement 1", "statement 2", "statement 3"]`; it('Should return null when there are no JSON array', () => { expect((0, extracter_1.extractJSONArrayResponse)(`hello world! { "key": "value" } end`)).toBe(undefined); }); it('Should extract a JSON array response with no chars in front or behind', () => { expect((0, extracter_1.extractJSONArrayResponse)(testJSONArray)).toEqual(testJSONArray); }); it('Should extract when there are chars both in front and behind', () => { expect((0, extracter_1.extractJSONArrayResponse)(`text in front ${testJSONArray} text behind`)).toEqual(testJSONArray); }); }); describe('extractBulletPointsResponse', () => { const testString = ` - bullet point 1 - bullet point 2 - bullet point 3 - with another dash in the middle. `; it('Should extract bullet point string into an array', () => { expect((0, extracter_1.extractBulletPointsResponse)(testString)).toEqual([ 'bullet point 1', 'bullet point 2', 'bullet point 3 - with another dash in the middle.', ]); }); });