diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6d5bdf4cfec8de7559fa706c81d67be6b070798a..e30126da7fbc36efd13f94d5e6a3b0e867437ac1 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -31,7 +31,12 @@ module.exports = { "@typescript-eslint/ban-types": "off", "no-array-constructor": "off", "@typescript-eslint/no-array-constructor": "off", - "@typescript-eslint/no-base-to-string": "off", + "@typescript-eslint/no-base-to-string": [ + "error", + { + ignoredTypeNames: ["Error", "RegExp", "URL", "URLSearchParams"], + }, + ], "@typescript-eslint/no-duplicate-enum-values": "off", "@typescript-eslint/no-duplicate-type-constituents": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/experimental/src/engines/query/JSONQueryEngine.ts b/packages/experimental/src/engines/query/JSONQueryEngine.ts index 4f5e469e511b835f0e8976da15f66a4b1c366ba9..f6a73cd8ea3623b9c16a8d7cfa3bfe7e9032d68f 100644 --- a/packages/experimental/src/engines/query/JSONQueryEngine.ts +++ b/packages/experimental/src/engines/query/JSONQueryEngine.ts @@ -162,18 +162,18 @@ export class JSONQueryEngine implements QueryEngine { const schema = this.getSchemaContext(); - const jsonPathResponseStr = await this.serviceContext.llm.complete({ + const { text: jsonPathResponse } = await this.serviceContext.llm.complete({ prompt: this.jsonPathPrompt({ query, schema }), }); if (this.verbose) { console.log( - `> JSONPath Instructions:\n\`\`\`\n${jsonPathResponseStr}\n\`\`\`\n`, + `> JSONPath Instructions:\n\`\`\`\n${jsonPathResponse}\n\`\`\`\n`, ); } const jsonPathOutput = await this.outputProcessor({ - llmOutput: jsonPathResponseStr.text, + llmOutput: jsonPathResponse, jsonValue: this.jsonValue, }); @@ -188,7 +188,7 @@ export class JSONQueryEngine implements QueryEngine { prompt: this.responseSynthesisPrompt({ query, jsonSchema: schema, - jsonPath: jsonPathResponseStr.text, + jsonPath: jsonPathResponse, jsonPathValue: JSON.stringify(jsonPathOutput), }), }); @@ -199,7 +199,7 @@ export class JSONQueryEngine implements QueryEngine { } const responseMetadata = { - jsonPathResponseStr, + jsonPathResponse, }; const response = EngineResponse.fromResponse(responseStr, false); diff --git a/packages/llamaindex/src/embeddings/JinaAIEmbedding.ts b/packages/llamaindex/src/embeddings/JinaAIEmbedding.ts index e1bc39972806cd99c0256e9b417d6e8586017c6a..c154477870afb5f5730b565028d993bc46c10b12 100644 --- a/packages/llamaindex/src/embeddings/JinaAIEmbedding.ts +++ b/packages/llamaindex/src/embeddings/JinaAIEmbedding.ts @@ -79,7 +79,7 @@ export class JinaAIEmbedding extends MultiModalEmbedding { private async getImageInput( image: ImageType, ): Promise<{ bytes: string } | { url: string }> { - if (isLocal(image)) { + if (isLocal(image) || image instanceof Blob) { const base64 = await imageToDataUrl(image); const bytes = base64.split(",")[1]; return { bytes }; diff --git a/packages/llamaindex/src/engines/query/RouterQueryEngine.ts b/packages/llamaindex/src/engines/query/RouterQueryEngine.ts index 6378734f6d7d6c9600259e7034c618ee4ba52a97..8c709b4f38f53e019da79add8a78e90aca895b1d 100644 --- a/packages/llamaindex/src/engines/query/RouterQueryEngine.ts +++ b/packages/llamaindex/src/engines/query/RouterQueryEngine.ts @@ -133,7 +133,7 @@ export class RouterQueryEngine extends PromptMixin implements QueryEngine { const responses: EngineResponse[] = []; for (let i = 0; i < result.selections.length; i++) { const engineInd = result.selections[i]; - const logStr = `Selecting query engine ${engineInd}: ${result.selections[i]}.`; + const logStr = `Selecting query engine ${engineInd.index}: ${result.selections[i].index}.`; if (this.verbose) { console.log(logStr + "\n"); diff --git a/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts b/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts index 82685eaaa9fddae02830fb5c6254b949ce5ec46c..79ad860b46b6c1833d97ebf2a1f7ac8b20d9842f 100644 --- a/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts +++ b/packages/llamaindex/src/engines/query/SubQuestionQueryEngine.ts @@ -119,15 +119,15 @@ export class SubQuestionQueryEngine return null; } - const responseText = await queryEngine?.call?.({ + const responseValue = await queryEngine?.call?.({ query: question, }); - if (!responseText) { + if (responseValue == null) { return null; } - const nodeText = `Sub question: ${question}\nResponse: ${responseText}`; + const nodeText = `Sub question: ${question}\nResponse: ${typeof responseValue === "string" ? responseValue : JSON.stringify(responseValue)}`; const node = new TextNode({ text: nodeText }); return { node, score: 0 }; } catch (error) { diff --git a/packages/llamaindex/src/evaluation/Relevancy.ts b/packages/llamaindex/src/evaluation/Relevancy.ts index f8b161306e82276372d2db5df20c50cbcaacdc1f..e738b328e4fab6c5e8d18b1551d76f4bf25b36f7 100644 --- a/packages/llamaindex/src/evaluation/Relevancy.ts +++ b/packages/llamaindex/src/evaluation/Relevancy.ts @@ -78,7 +78,7 @@ export class RelevancyEvaluator extends PromptMixin implements BaseEvaluator { serviceContext: this.serviceContext, }); - const queryResponse = `Question: ${query}\nResponse: ${response}`; + const queryResponse = `Question: ${extractText(query)}\nResponse: ${response}`; const queryEngine = index.asQueryEngine(); diff --git a/packages/llamaindex/src/readers/JSONReader.ts b/packages/llamaindex/src/readers/JSONReader.ts index fb0333a4a8924e83f8158f9b43afc3bdab28da25..13c54cd2bfcdc2dd101a3556a7a2c789cc9ee9e0 100644 --- a/packages/llamaindex/src/readers/JSONReader.ts +++ b/packages/llamaindex/src/readers/JSONReader.ts @@ -185,7 +185,7 @@ export class JSONReader<T extends JSONValue> extends FileReader { return jsonStr; } catch (e) { throw new JSONStringifyError( - `Error stringifying JSON: ${e} in "${data}"`, + `Error stringifying JSON: ${e} in "${JSON.stringify(data)}"`, ); } }