diff --git a/src/deep-research.ts b/src/deep-research.ts index f27b26b..924bf96 100644 --- a/src/deep-research.ts +++ b/src/deep-research.ts @@ -98,9 +98,11 @@ async function processSerpResult({ model: getModel(), abortSignal: AbortSignal.timeout(60_000), system: systemPrompt(), - prompt: `Given the following contents from a SERP search for the query ${query}, generate a list of learnings from the contents. Return a maximum of ${numLearnings} learnings, but feel free to return less if the contents are clear. Make sure each learning is unique and not similar to each other. The learnings should be concise and to the point, as detailed and information dense as possible. Make sure to include any entities like people, places, companies, products, things, etc in the learnings, as well as any exact metrics, numbers, or dates. The learnings will be used to research the topic further.\n\n${contents - .map(content => `\n${content}\n`) - .join('\n')}`, + prompt: trimPrompt( + `Given the following contents from a SERP search for the query ${query}, generate a list of learnings from the contents. Return a maximum of ${numLearnings} learnings, but feel free to return less if the contents are clear. Make sure each learning is unique and not similar to each other. The learnings should be concise and to the point, as detailed and information dense as possible. Make sure to include any entities like people, places, companies, products, things, etc in the learnings, as well as any exact metrics, numbers, or dates. The learnings will be used to research the topic further.\n\n${contents + .map(content => `\n${content}\n`) + .join('\n')}`, + ), schema: z.object({ learnings: z .array(z.string()) @@ -126,17 +128,16 @@ export async function writeFinalReport({ learnings: string[]; visitedUrls: string[]; }) { - const learningsString = trimPrompt( - learnings - .map(learning => `\n${learning}\n`) - .join('\n'), - 150_000, - ); + const learningsString = learnings + .map(learning => `\n${learning}\n`) + .join('\n'); const res = await generateObject({ model: getModel(), system: systemPrompt(), - prompt: `Given the following prompt from the user, write a final report on the topic using the learnings from research. Make it as as detailed as possible, aim for 3 or more pages, include ALL the learnings from research:\n\n${prompt}\n\nHere are all the learnings from previous research:\n\n\n${learningsString}\n`, + prompt: trimPrompt( + `Given the following prompt from the user, write a final report on the topic using the learnings from research. Make it as as detailed as possible, aim for 3 or more pages, include ALL the learnings from research:\n\n${prompt}\n\nHere are all the learnings from previous research:\n\n\n${learningsString}\n`, + ), schema: z.object({ reportMarkdown: z .string() @@ -156,17 +157,16 @@ export async function writeFinalAnswer({ prompt: string; learnings: string[]; }) { - const learningsString = trimPrompt( - learnings - .map(learning => `\n${learning}\n`) - .join('\n'), - 150_000, - ); + const learningsString = learnings + .map(learning => `\n${learning}\n`) + .join('\n'); const res = await generateObject({ model: getModel(), system: systemPrompt(), - prompt: `Given the following prompt from the user, write a final answer on the topic using the learnings from research. Follow the format specified in the prompt. Do not yap or babble or include any other text than the answer besides the format specified in the prompt. Keep the answer as concise as possible - usually it should be just a few words or maximum a sentence. Try to follow the format specified in the prompt (for example, if the prompt is using Latex, the answer should be in Latex. If the prompt gives multiple answer choices, the answer should be one of the choices).\n\n${prompt}\n\nHere are all the learnings from research on the topic that you can use to help answer the prompt:\n\n\n${learningsString}\n`, + prompt: trimPrompt( + `Given the following prompt from the user, write a final answer on the topic using the learnings from research. Follow the format specified in the prompt. Do not yap or babble or include any other text than the answer besides the format specified in the prompt. Keep the answer as concise as possible - usually it should be just a few words or maximum a sentence. Try to follow the format specified in the prompt (for example, if the prompt is using Latex, the answer should be in Latex. If the prompt gives multiple answer choices, the answer should be one of the choices).\n\n${prompt}\n\nHere are all the learnings from research on the topic that you can use to help answer the prompt:\n\n\n${learningsString}\n`, + ), schema: z.object({ exactAnswer: z .string() diff --git a/src/run.ts b/src/run.ts index 6815ac0..e2756ae 100644 --- a/src/run.ts +++ b/src/run.ts @@ -48,10 +48,11 @@ async function run() { await askQuestion('Enter research depth (recommended 1-5, default 2): '), 10, ) || 2; + const reportAnswer = await askQuestion( + 'Do you want to generate a long report or a specific answer? (report/answer, default report): ', + ); const isReport = - (await askQuestion( - 'Do you want to generate a long report or a specific answer? (report/answer, default report): ', - )) === 'report'; + reportAnswer === '' || reportAnswer.toLowerCase() === 'report'; let combinedQuery = initialQuery; if (isReport) {