From 824d090a7f777807e3ec7821f7321a74a9cc48f1 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Thu, 19 Dec 2024 13:43:41 -0800 Subject: [PATCH] Format --- .../src/structured_query/functional.ts | 30 +++++++++++++++---- .../structured_query/tests/functional.test.ts | 26 ++++++++++------ .../src/structured_query/tests/utils.test.ts | 2 +- langchain-core/src/structured_query/utils.ts | 2 +- .../tests/query_chain.int.test.ts | 8 ++--- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/langchain-core/src/structured_query/functional.ts b/langchain-core/src/structured_query/functional.ts index 30b0fef887e2..2475ba1ff471 100644 --- a/langchain-core/src/structured_query/functional.ts +++ b/langchain-core/src/structured_query/functional.ts @@ -65,7 +65,7 @@ export class FunctionalTranslator extends BaseTranslator { formatFunction(): string { throw new Error("Not implemented"); } - + /** * Returns the allowed comparators for a given data type. * @param input The input value to get the allowed comparators for. @@ -74,10 +74,24 @@ export class FunctionalTranslator extends BaseTranslator { getAllowedComparatorsForType(inputType: string): Comparator[] { switch (inputType) { case "string": { - return [Comparators.eq, Comparators.ne, Comparators.gt, Comparators.gte, Comparators.lt, Comparators.lte]; + return [ + Comparators.eq, + Comparators.ne, + Comparators.gt, + Comparators.gte, + Comparators.lt, + Comparators.lte, + ]; } case "number": { - return [Comparators.eq, Comparators.ne, Comparators.gt, Comparators.gte, Comparators.lt, Comparators.lte]; + return [ + Comparators.eq, + Comparators.ne, + Comparators.gt, + Comparators.gte, + Comparators.lt, + Comparators.lte, + ]; } case "boolean": { return [Comparators.eq, Comparators.ne]; @@ -87,7 +101,7 @@ export class FunctionalTranslator extends BaseTranslator { } } } - + /** * Returns a function that performs a comparison based on the provided * comparator. @@ -181,8 +195,12 @@ export class FunctionalTranslator extends BaseTranslator { const { comparator, attribute, value } = comparison; const undefinedTrue = [Comparators.ne]; if (this.allowedComparators.includes(comparator)) { - if (!this.getAllowedComparatorsForType(typeof value).includes(comparator)) { - throw new Error(`'${comparator}' comparator not allowed to be used with ${typeof value}`); + if ( + !this.getAllowedComparatorsForType(typeof value).includes(comparator) + ) { + throw new Error( + `'${comparator}' comparator not allowed to be used with ${typeof value}` + ); } const comparatorFunction = this.getComparatorFunction(comparator); return (document: Document) => { diff --git a/langchain-core/src/structured_query/tests/functional.test.ts b/langchain-core/src/structured_query/tests/functional.test.ts index cf457168c2ec..2db797093c80 100644 --- a/langchain-core/src/structured_query/tests/functional.test.ts +++ b/langchain-core/src/structured_query/tests/functional.test.ts @@ -47,15 +47,19 @@ describe("FunctionalTranslator", () => { number: "numberValue", boolean: "booleanValue", }; - - const inputValuesByAttribute: { [key in string]: string | number | boolean } = { + + const inputValuesByAttribute: { + [key in string]: string | number | boolean; + } = { stringValue: "value", numberValue: 1, booleanValue: true, }; - + // documents that will match against the comparison - const validDocumentsByComparator: { [key in string]: Document>[] } = { + const validDocumentsByComparator: { + [key in string]: Document>[]; + } = { [Comparators.eq]: [ new Document({ pageContent: "", @@ -137,9 +141,11 @@ describe("FunctionalTranslator", () => { }), ], }; - + // documents that will not match against the comparison - const invalidDocumentsByComparator: { [key in string]: Document>[] } = { + const invalidDocumentsByComparator: { + [key in string]: Document>[]; + } = { [Comparators.eq]: [ new Document({ pageContent: "", @@ -201,8 +207,10 @@ describe("FunctionalTranslator", () => { }), ], }; - - function generateComparatorTestsForType(type: "string" | "number" | "boolean") { + + function generateComparatorTestsForType( + type: "string" | "number" | "boolean" + ) { const comparators = translator.getAllowedComparatorsForType(type); for (const comparator of comparators) { const attribute = attributesByType[type]; @@ -237,7 +245,7 @@ describe("FunctionalTranslator", () => { } } } - + generateComparatorTestsForType("string"); generateComparatorTestsForType("number"); generateComparatorTestsForType("boolean"); diff --git a/langchain-core/src/structured_query/tests/utils.test.ts b/langchain-core/src/structured_query/tests/utils.test.ts index 71c6458e34f7..53b413702c2f 100644 --- a/langchain-core/src/structured_query/tests/utils.test.ts +++ b/langchain-core/src/structured_query/tests/utils.test.ts @@ -56,7 +56,7 @@ test("Casting values correctly", () => { expect(typeof value).toBe("number"); expect(isFloat(value)).toBe(true); }); - + booleanBoolean.map(castValue).forEach((value) => { expect(typeof value).toBe("boolean"); expect(isBoolean(value)).toBe(true); diff --git a/langchain-core/src/structured_query/utils.ts b/langchain-core/src/structured_query/utils.ts index b70df772be4c..92c9639b365b 100644 --- a/langchain-core/src/structured_query/utils.ts +++ b/langchain-core/src/structured_query/utils.ts @@ -76,7 +76,7 @@ export function isString(value: unknown): boolean { * Checks if the provided value is a boolean. */ export function isBoolean(value: unknown): boolean { - return typeof value === "boolean"; + return typeof value === "boolean"; } /** diff --git a/langchain/src/chains/query_constructor/tests/query_chain.int.test.ts b/langchain/src/chains/query_constructor/tests/query_chain.int.test.ts index 88be5ae7b379..59279fe70ef1 100644 --- a/langchain/src/chains/query_constructor/tests/query_chain.int.test.ts +++ b/langchain/src/chains/query_constructor/tests/query_chain.int.test.ts @@ -76,10 +76,10 @@ test("Query Chain Test", async () => { type: "number", }, { - name: "isReleased", - description: "Whether the movie has been released", - type: "boolean", - } + name: "isReleased", + description: "Whether the movie has been released", + type: "boolean", + }, ]; const documentContents = "Brief summary of a movie";