From f593546864358a072d502e704bca0ce7c14aff76 Mon Sep 17 00:00:00 2001 From: AnotiaWang Date: Tue, 18 Feb 2025 12:57:56 +0800 Subject: [PATCH] fix(deep-research): `searchLanguage` is missing when recursively calling `deepResearch` --- lib/deep-research.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/deep-research.ts b/lib/deep-research.ts index 7c6dbda..87ebfe5 100644 --- a/lib/deep-research.ts +++ b/lib/deep-research.ts @@ -92,22 +92,24 @@ export function generateSearchQueries({ const schema = z.object({ queries: z .array( - z.object({ - query: z.string().describe('The SERP query'), - researchGoal: z - .string() - .describe( - 'First talk about the goal of the research that this query is meant to accomplish, then go deeper into how to advance the research once the results are found, mention additional research directions. Be as specific as possible, especially for additional research directions.', - ), - }), + z + .object({ + query: z.string().describe('The SERP query.'), + researchGoal: z + .string() + .describe( + 'First talk about the goal of the research that this query is meant to accomplish, then go deeper into how to advance the research once the results are found, mention additional research directions. Be as specific as possible, especially for additional research directions.', + ), + }) + .required({ query: true, researchGoal: true }), ) .describe(`List of SERP queries, max of ${numQueries}`), }) const jsonSchema = JSON.stringify(zodToJsonSchema(schema)) let lp = languagePrompt(language) - if (searchLanguage !== language) { - lp += `Use ${searchLanguage} for the SERP queries.` + if (searchLanguage && searchLanguage !== language) { + lp += ` Use ${searchLanguage} for the SERP queries.` } const prompt = [ `Given the following prompt from the user, generate a list of SERP queries to research the topic. Return a maximum of ${numQueries} queries, but feel free to return less if the original prompt is clear. Make sure each query is unique and not similar to each other: ${query}\n\n`, @@ -443,6 +445,7 @@ export async function deepResearch({ currentDepth: nextDepth, nodeId: childNodeId(nodeId, i), languageCode, + searchLanguage, }) return r } catch (error) {