feat(server): enable web search for 4.1 (#11825)

This commit is contained in:
darkskygit
2025-04-22 14:49:46 +00:00
parent bbdea71686
commit 597b27c22f
10 changed files with 317 additions and 99 deletions
@@ -1112,7 +1112,11 @@ test('CitationParser should replace citation placeholders with URLs', t => {
const citations = ['https://example1.com', 'https://example2.com'];
const parser = new CitationParser();
const result = parser.parse(content, citations) + parser.end();
for (const citation of citations) {
parser.push(citation);
}
const result = parser.parse(content) + parser.end();
const expected = [
'This is [a] test sentence with [citations [^1]] and [^2] and [3].',
@@ -1147,8 +1151,12 @@ test('CitationParser should replace chunks of citation placeholders with URLs',
];
const parser = new CitationParser();
for (const citation of citations) {
parser.push(citation);
}
let result = contents.reduce((acc, current) => {
return acc + parser.parse(current, citations);
return acc + parser.parse(current);
}, '');
result += parser.end();
@@ -1175,7 +1183,11 @@ test('CitationParser should not replace citation already with URLs', t => {
];
const parser = new CitationParser();
const result = parser.parse(content, citations) + parser.end();
for (const citation of citations) {
parser.push(citation);
}
const result = parser.parse(content) + parser.end();
const expected = [
content,
@@ -1199,8 +1211,12 @@ test('CitationParser should not replace chunks of citation already with URLs', t
];
const parser = new CitationParser();
for (const citation of citations) {
parser.push(citation);
}
let result = contents.reduce((acc, current) => {
return acc + parser.parse(current, citations);
return acc + parser.parse(current);
}, '');
result += parser.end();
@@ -1213,6 +1229,26 @@ test('CitationParser should not replace chunks of citation already with URLs', t
t.is(result, expected);
});
test('CitationParser should replace openai style reference chunks', t => {
const contents = [
'This is [a] test sentence with citations ',
'([example1.com](https://example1.com))',
];
const parser = new CitationParser();
let result = contents.reduce((acc, current) => {
return acc + parser.parse(current);
}, '');
result += parser.end();
const expected = [
contents[0] + '[^1]',
`[^1]: {"type":"url","url":"${encodeURIComponent('https://example1.com')}"}`,
].join('\n');
t.is(result, expected);
});
// ==================== context ====================
test('should be able to manage context', async t => {
const { context, prompt, session, event, jobs, storage } = t.context;