Skip to content
Snippets Groups Projects
Unverified Commit 62b874e1 authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

fix: enforce `no-base-to-string` (#1097)

parent 9c9e9b4e
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,12 @@ module.exports = { ...@@ -31,7 +31,12 @@ module.exports = {
"@typescript-eslint/ban-types": "off", "@typescript-eslint/ban-types": "off",
"no-array-constructor": "off", "no-array-constructor": "off",
"@typescript-eslint/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-enum-values": "off",
"@typescript-eslint/no-duplicate-type-constituents": "off", "@typescript-eslint/no-duplicate-type-constituents": "off",
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
......
...@@ -162,18 +162,18 @@ export class JSONQueryEngine implements QueryEngine { ...@@ -162,18 +162,18 @@ export class JSONQueryEngine implements QueryEngine {
const schema = this.getSchemaContext(); const schema = this.getSchemaContext();
const jsonPathResponseStr = await this.serviceContext.llm.complete({ const { text: jsonPathResponse } = await this.serviceContext.llm.complete({
prompt: this.jsonPathPrompt({ query, schema }), prompt: this.jsonPathPrompt({ query, schema }),
}); });
if (this.verbose) { if (this.verbose) {
console.log( console.log(
`> JSONPath Instructions:\n\`\`\`\n${jsonPathResponseStr}\n\`\`\`\n`, `> JSONPath Instructions:\n\`\`\`\n${jsonPathResponse}\n\`\`\`\n`,
); );
} }
const jsonPathOutput = await this.outputProcessor({ const jsonPathOutput = await this.outputProcessor({
llmOutput: jsonPathResponseStr.text, llmOutput: jsonPathResponse,
jsonValue: this.jsonValue, jsonValue: this.jsonValue,
}); });
...@@ -188,7 +188,7 @@ export class JSONQueryEngine implements QueryEngine { ...@@ -188,7 +188,7 @@ export class JSONQueryEngine implements QueryEngine {
prompt: this.responseSynthesisPrompt({ prompt: this.responseSynthesisPrompt({
query, query,
jsonSchema: schema, jsonSchema: schema,
jsonPath: jsonPathResponseStr.text, jsonPath: jsonPathResponse,
jsonPathValue: JSON.stringify(jsonPathOutput), jsonPathValue: JSON.stringify(jsonPathOutput),
}), }),
}); });
...@@ -199,7 +199,7 @@ export class JSONQueryEngine implements QueryEngine { ...@@ -199,7 +199,7 @@ export class JSONQueryEngine implements QueryEngine {
} }
const responseMetadata = { const responseMetadata = {
jsonPathResponseStr, jsonPathResponse,
}; };
const response = EngineResponse.fromResponse(responseStr, false); const response = EngineResponse.fromResponse(responseStr, false);
......
...@@ -79,7 +79,7 @@ export class JinaAIEmbedding extends MultiModalEmbedding { ...@@ -79,7 +79,7 @@ export class JinaAIEmbedding extends MultiModalEmbedding {
private async getImageInput( private async getImageInput(
image: ImageType, image: ImageType,
): Promise<{ bytes: string } | { url: string }> { ): Promise<{ bytes: string } | { url: string }> {
if (isLocal(image)) { if (isLocal(image) || image instanceof Blob) {
const base64 = await imageToDataUrl(image); const base64 = await imageToDataUrl(image);
const bytes = base64.split(",")[1]; const bytes = base64.split(",")[1];
return { bytes }; return { bytes };
......
...@@ -133,7 +133,7 @@ export class RouterQueryEngine extends PromptMixin implements QueryEngine { ...@@ -133,7 +133,7 @@ export class RouterQueryEngine extends PromptMixin implements QueryEngine {
const responses: EngineResponse[] = []; const responses: EngineResponse[] = [];
for (let i = 0; i < result.selections.length; i++) { for (let i = 0; i < result.selections.length; i++) {
const engineInd = result.selections[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) { if (this.verbose) {
console.log(logStr + "\n"); console.log(logStr + "\n");
......
...@@ -119,15 +119,15 @@ export class SubQuestionQueryEngine ...@@ -119,15 +119,15 @@ export class SubQuestionQueryEngine
return null; return null;
} }
const responseText = await queryEngine?.call?.({ const responseValue = await queryEngine?.call?.({
query: question, query: question,
}); });
if (!responseText) { if (responseValue == null) {
return 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 }); const node = new TextNode({ text: nodeText });
return { node, score: 0 }; return { node, score: 0 };
} catch (error) { } catch (error) {
......
...@@ -78,7 +78,7 @@ export class RelevancyEvaluator extends PromptMixin implements BaseEvaluator { ...@@ -78,7 +78,7 @@ export class RelevancyEvaluator extends PromptMixin implements BaseEvaluator {
serviceContext: this.serviceContext, serviceContext: this.serviceContext,
}); });
const queryResponse = `Question: ${query}\nResponse: ${response}`; const queryResponse = `Question: ${extractText(query)}\nResponse: ${response}`;
const queryEngine = index.asQueryEngine(); const queryEngine = index.asQueryEngine();
......
...@@ -185,7 +185,7 @@ export class JSONReader<T extends JSONValue> extends FileReader { ...@@ -185,7 +185,7 @@ export class JSONReader<T extends JSONValue> extends FileReader {
return jsonStr; return jsonStr;
} catch (e) { } catch (e) {
throw new JSONStringifyError( throw new JSONStringifyError(
`Error stringifying JSON: ${e} in "${data}"`, `Error stringifying JSON: ${e} in "${JSON.stringify(data)}"`,
); );
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment