mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
fix: improve prompting
This commit is contained in:
parent
fd40c7b020
commit
7f208c5072
60
src/agent.ts
60
src/agent.ts
@ -111,7 +111,7 @@ function getPrompt(
|
|||||||
allowRead: boolean = true,
|
allowRead: boolean = true,
|
||||||
allowSearch: boolean = true,
|
allowSearch: boolean = true,
|
||||||
badContext?: { question: string, answer: string, evaluation: string, recap: string; blame: string; improvement: string; }[],
|
badContext?: { question: string, answer: string, evaluation: string, recap: string; blame: string; improvement: string; }[],
|
||||||
knowledge?: { question: string; answer: string; references: any[]}[],
|
knowledge?: { question: string; answer: string; references: any[] }[],
|
||||||
allURLs?: Record<string, string>,
|
allURLs?: Record<string, string>,
|
||||||
beastMode?: boolean
|
beastMode?: boolean
|
||||||
): string {
|
): string {
|
||||||
@ -295,6 +295,7 @@ function removeHTMLtags(text: string) {
|
|||||||
return text.replace(/<[^>]*>?/gm, '');
|
return text.replace(/<[^>]*>?/gm, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getResponse(question: string, tokenBudget: number = 1_000_000,
|
export async function getResponse(question: string, tokenBudget: number = 1_000_000,
|
||||||
maxBadAttempts: number = 3,
|
maxBadAttempts: number = 3,
|
||||||
existingContext?: Partial<TrackerContext>): Promise<{ result: StepAction; context: TrackerContext }> {
|
existingContext?: Partial<TrackerContext>): Promise<{ result: StepAction; context: TrackerContext }> {
|
||||||
@ -537,42 +538,51 @@ But then you realized you have asked them before. You decided to to think out of
|
|||||||
const searchResults = [];
|
const searchResults = [];
|
||||||
for (const query of keywordsQueries) {
|
for (const query of keywordsQueries) {
|
||||||
console.log(`Search query: ${query}`);
|
console.log(`Search query: ${query}`);
|
||||||
|
|
||||||
let results;
|
let results;
|
||||||
if (SEARCH_PROVIDER === 'duck') {
|
switch (SEARCH_PROVIDER) {
|
||||||
results = await duckSearch(query, {
|
case 'duck':
|
||||||
safeSearch: SafeSearchType.STRICT
|
results = await duckSearch(query, {safeSearch: SafeSearchType.STRICT});
|
||||||
});
|
break;
|
||||||
} else {
|
case 'brave':
|
||||||
const {response} = await braveSearch(query);
|
try {
|
||||||
await sleep(STEP_SLEEP);
|
const {response} = await braveSearch(query);
|
||||||
results = {
|
results = {
|
||||||
results: response.web.results.map(r => ({
|
results: response.web?.results?.map(r => ({
|
||||||
title: r.title,
|
title: r.title,
|
||||||
url: r.url,
|
url: r.url,
|
||||||
description: r.description
|
description: r.description
|
||||||
}))
|
})) || []
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Brave search failed:', error);
|
||||||
|
results = {results: []};
|
||||||
|
}
|
||||||
|
await sleep(STEP_SLEEP)
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
results = {results: []};
|
||||||
}
|
}
|
||||||
const minResults = results.results.map(r => ({
|
const minResults = results.results.map(r => ({
|
||||||
title: r.title,
|
title: r.title,
|
||||||
url: r.url,
|
url: r.url,
|
||||||
description: r.description,
|
description: r.description
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (const r of minResults) {
|
Object.assign(allURLs, Object.fromEntries(
|
||||||
allURLs[r.url] = r.title;
|
minResults.map(r => [r.url, r.title])
|
||||||
}
|
));
|
||||||
searchResults.push({query, results: minResults});
|
searchResults.push({query, results: minResults});
|
||||||
allKeywords.push(query);
|
allKeywords.push(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
allKnowledge.push({
|
allKnowledge.push({
|
||||||
question: `What do Internet say about ${thisStep.searchQuery}?`,
|
question: `What do Internet say about ${thisStep.searchQuery}?`,
|
||||||
answer: removeHTMLtags(searchResults.map(r => r.results.map(r => r.description).join('; ')).join('; ')),
|
answer: removeHTMLtags(searchResults.map(r => r.results.map(r => r.description).join('; ')).join('; ')),
|
||||||
// flatten into one url list, and take unique urls
|
// flatten into one url list, and take unique urls
|
||||||
references: searchResults.map(r => r.results.map(r => r.url)).flat().filter((v, i, a) => a.indexOf(v) === i),
|
references: searchResults.map(r => r.results.map(r => r.url)).flat().filter((v, i, a) => a.indexOf(v) === i),
|
||||||
type: 'side-info'
|
type: 'side-info'
|
||||||
});
|
});
|
||||||
|
|
||||||
diaryContext.push(`
|
diaryContext.push(`
|
||||||
At step ${step}, you took the **search** action and look for external information for the question: "${currentQuestion}".
|
At step ${step}, you took the **search** action and look for external information for the question: "${currentQuestion}".
|
||||||
|
|||||||
@ -79,7 +79,7 @@ Function FilterSetA(setA, setB, threshold):
|
|||||||
- Different title/body filters (intitle: vs inbody:)
|
- Different title/body filters (intitle: vs inbody:)
|
||||||
</similarity-definition>
|
</similarity-definition>
|
||||||
|
|
||||||
Now, run FilterSetA on the following:
|
Now with threshold set to 0.2; run FilterSetA on the following:
|
||||||
SetA: ${JSON.stringify(newQueries)}
|
SetA: ${JSON.stringify(newQueries)}
|
||||||
SetB: ${JSON.stringify(existingQueries)}`;
|
SetB: ${JSON.stringify(existingQueries)}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user