mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2026-03-22 07:29:35 +08:00
feat: improve url ranking, fix eval bugs
This commit is contained in:
10
src/agent.ts
10
src/agent.ts
@@ -554,14 +554,10 @@ But then you realized you have asked them before. You decided to to think out of
|
||||
|
||||
try {
|
||||
let siteQuery = query
|
||||
if (allURLs && Object.keys(allURLs).length > 0) {
|
||||
// rerank urls
|
||||
weightedURLs = rankURLs(getUnvisitedURLs(allURLs, visitedURLs), {
|
||||
question: currentQuestion
|
||||
}, context);
|
||||
}
|
||||
|
||||
const topHosts = Object.entries(countUrlParts(weightedURLs).hostnameCount).sort((a, b) => b[1] - a[1]);
|
||||
const topHosts = Object.entries(countUrlParts(
|
||||
Object.entries(allURLs).map(([, result]) => result)
|
||||
).hostnameCount).sort((a, b) => b[1] - a[1]);
|
||||
console.log(topHosts)
|
||||
if (topHosts.length > 0 && Math.random() < 0.6 && !query.includes('site:')) {
|
||||
// explore-exploit
|
||||
|
||||
@@ -2,8 +2,8 @@ import {AnswerAction} from "../types";
|
||||
import i18nJSON from './i18n.json';
|
||||
|
||||
export function buildMdFromAnswer(answer: AnswerAction) {
|
||||
// Standard footnote regex - updated to handle both [^1] and [1^] formats
|
||||
const footnoteRegex = /\[(\^(\d+)|(\d+)\^)]/g;
|
||||
// Standard footnote regex - updated to handle [^1], [1^], and [1] formats
|
||||
const footnoteRegex = /\[(\^(\d+)|(\d+)\^|(\d+))]/g;
|
||||
|
||||
// New regex to catch grouped footnotes like [^1, ^2, ^3] or [^1,^2,^3]
|
||||
const groupedFootnoteRegex = /\[\^(\d+)(?:,\s*\^(\d+))+]/g;
|
||||
@@ -35,8 +35,10 @@ export function buildMdFromAnswer(answer: AnswerAction) {
|
||||
.replace(footnoteRegex, '');
|
||||
}
|
||||
|
||||
// Normalize footnotes first (convert [1^] to [^1] format)
|
||||
let processedAnswer = answer.answer.replace(/\[(\d+)\^]/g, (_, num) => `[^${num}]`);
|
||||
// Normalize footnotes first (convert [1^] to [^1] format and [1] to [^1] format)
|
||||
let processedAnswer = answer.answer
|
||||
.replace(/\[(\d+)\^]/g, (_, num) => `[^${num}]`)
|
||||
.replace(/\[(\d+)]/g, (_, num) => `[^${num}]`);
|
||||
|
||||
// Fix grouped footnotes
|
||||
processedAnswer = processedAnswer.replace(groupedFootnoteRegex, (match) => {
|
||||
@@ -133,6 +135,7 @@ ${correctedAnswer}
|
||||
${formatReferences(answer.references)}
|
||||
`.trim();
|
||||
}
|
||||
|
||||
export const removeExtraLineBreaks = (text: string) => {
|
||||
return text.replace(/\n{2,}/gm, '\n\n');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user