fixed issue with trim prompt not working as intended

This commit is contained in:
David Zhang
2025-03-13 01:34:34 -07:00
parent f937513046
commit df09cfb4bd
2 changed files with 21 additions and 20 deletions

View File

@@ -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>${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>${contents
.map(content => `<content>\n${content}\n</content>`)
.join('\n')}</contents>`,
prompt: trimPrompt(
`Given the following contents from a SERP search for the query <query>${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>${contents
.map(content => `<content>\n${content}\n</content>`)
.join('\n')}</contents>`,
),
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 => `<learning>\n${learning}\n</learning>`)
.join('\n'),
150_000,
);
const learningsString = learnings
.map(learning => `<learning>\n${learning}\n</learning>`)
.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>${prompt}</prompt>\n\nHere are all the learnings from previous research:\n\n<learnings>\n${learningsString}\n</learnings>`,
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>${prompt}</prompt>\n\nHere are all the learnings from previous research:\n\n<learnings>\n${learningsString}\n</learnings>`,
),
schema: z.object({
reportMarkdown: z
.string()
@@ -156,17 +157,16 @@ export async function writeFinalAnswer({
prompt: string;
learnings: string[];
}) {
const learningsString = trimPrompt(
learnings
.map(learning => `<learning>\n${learning}\n</learning>`)
.join('\n'),
150_000,
);
const learningsString = learnings
.map(learning => `<learning>\n${learning}\n</learning>`)
.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>${prompt}</prompt>\n\nHere are all the learnings from research on the topic that you can use to help answer the prompt:\n\n<learnings>\n${learningsString}\n</learnings>`,
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>${prompt}</prompt>\n\nHere are all the learnings from research on the topic that you can use to help answer the prompt:\n\n<learnings>\n${learningsString}\n</learnings>`,
),
schema: z.object({
exactAnswer: z
.string()

View File

@@ -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) {