mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
chore: first commit
This commit is contained in:
@@ -259,7 +259,8 @@ function removeAllLineBreaks(text: string) {
|
|||||||
return text.replace(/(\r\n|\n|\r)/gm, " ");
|
return text.replace(/(\r\n|\n|\r)/gm, " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getResponse(question: string) {
|
async function getResponse(question: string, tokenBudget: number = 1000000, maxBadAttempts: number = 3) {
|
||||||
|
let totalTokens = 0;
|
||||||
let step = 0;
|
let step = 0;
|
||||||
let totalStep = 0;
|
let totalStep = 0;
|
||||||
let badAttempts = 0;
|
let badAttempts = 0;
|
||||||
@@ -270,14 +271,14 @@ async function getResponse(question: string) {
|
|||||||
const badContext = [];
|
const badContext = [];
|
||||||
let diaryContext = [];
|
let diaryContext = [];
|
||||||
const allURLs: Record<string, string> = {};
|
const allURLs: Record<string, string> = {};
|
||||||
const currentQuestion = gaps.length > 0 ? gaps.shift()! : question;
|
while (totalTokens < tokenBudget) {
|
||||||
while (gaps.length > 0 || currentQuestion === question) {
|
|
||||||
// add 1s delay to avoid rate limiting
|
// add 1s delay to avoid rate limiting
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
step++;
|
step++;
|
||||||
totalStep++;
|
totalStep++;
|
||||||
console.log(`Step ${totalStep}: Gap questions ${JSON.stringify(gaps)}`);
|
console.log(`Step ${totalStep}: Gap questions ${JSON.stringify(gaps)}`);
|
||||||
const allowReflect = gaps.length <= 1;
|
const allowReflect = gaps.length <= 1;
|
||||||
|
const currentQuestion = gaps.length > 0 ? gaps.shift()! : question;
|
||||||
// update all urls with buildURLMap
|
// update all urls with buildURLMap
|
||||||
const allowRead = Object.keys(allURLs).length > 0;
|
const allowRead = Object.keys(allURLs).length > 0;
|
||||||
const prompt = getPrompt(
|
const prompt = getPrompt(
|
||||||
@@ -321,7 +322,7 @@ async function getResponse(question: string) {
|
|||||||
|
|
||||||
|
|
||||||
if (currentQuestion === question) {
|
if (currentQuestion === question) {
|
||||||
if (badAttempts >= 3) {
|
if (badAttempts >= maxBadAttempts) {
|
||||||
// EXIT POINT OF THE PROGRAM!!!!
|
// EXIT POINT OF THE PROGRAM!!!!
|
||||||
diaryContext.push(`
|
diaryContext.push(`
|
||||||
At step ${step} and ${badAttempts} attempts, you took **answer** action and found an answer, not a perfect one but good enough to answer the original question:
|
At step ${step} and ${badAttempts} attempts, you took **answer** action and found an answer, not a perfect one but good enough to answer the original question:
|
||||||
|
|||||||
Reference in New Issue
Block a user