Skip to content

Commit 347beda

Browse files
committed
feat: only hostnames
1 parent 45bcbf9 commit 347beda

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

src/agent.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414
StepAction,
1515
AnswerAction,
1616
KnowledgeItem,
17-
SearchResult,
1817
EvaluationType,
1918
BoostedSearchSnippet,
20-
SearchSnippet, EvaluationResponse, Reference, SERPQuery, RepeatEvaluationType
19+
SearchSnippet, EvaluationResponse, Reference, SERPQuery, RepeatEvaluationType, UnNormalizedSearchSnippet
2120
} from "./types";
2221
import {TrackerContext} from "./types";
2322
import {search} from "./tools/jina-search";
@@ -254,7 +253,7 @@ async function updateReferences(thisStep: AnswerAction, allURLs: Record<string,
254253
.replace(/\s+/g, ' '),
255254
title: allURLs[normalizedUrl]?.title || '',
256255
url: normalizedUrl,
257-
dateTime: ref?.dateTime || ''
256+
dateTime: ref?.dateTime || allURLs[normalizedUrl]?.date || '',
258257
};
259258
})
260259
.filter(Boolean) as Reference[]; // Add type assertion here
@@ -284,7 +283,7 @@ async function executeSearchQueries(
284283
context.actionTracker.trackThink('search_for', SchemaGen.languageCode, {keywords: uniqQOnly.join(', ')});
285284
let utilityScore = 0;
286285
for (const query of keywordsQueries) {
287-
let results: SearchResult[] = [];
286+
let results: UnNormalizedSearchSnippet[] = [];
288287
const oldQuery = query.q;
289288
if (onlyHostnames && onlyHostnames.length > 0) {
290289
query.q = `${query.q} site:${onlyHostnames.join(' OR site:')}`;
@@ -321,15 +320,16 @@ async function executeSearchQueries(
321320

322321
const minResults: SearchSnippet[] = results
323322
.map(r => {
324-
const url = normalizeUrl('url' in r ? r.url : r.link);
323+
const url = normalizeUrl('url' in r ? r.url! : r.link!);
325324
if (!url) return null; // Skip invalid URLs
326325

327326
return {
328327
title: r.title,
329328
url,
330329
description: 'description' in r ? r.description : r.snippet,
331-
weight: 1
332-
};
330+
weight: 1,
331+
date: r.date,
332+
} as SearchSnippet;
333333
})
334334
.filter(Boolean) as SearchSnippet[]; // Filter out null entries and assert type
335335

@@ -798,7 +798,7 @@ You decided to think out of the box or cut from a completely different angle.
798798
.map(url => normalizeUrl(url))
799799
.filter(url => url && !visitedURLs.includes(url)) as string[];
800800

801-
thisStep.URLTargets = [...new Set([...thisStep.URLTargets, ...weightedURLs.map(r => r.url)])].slice(0, MAX_URLS_PER_STEP);
801+
thisStep.URLTargets = [...new Set([...thisStep.URLTargets, ...weightedURLs.map(r => r.url!)])].slice(0, MAX_URLS_PER_STEP);
802802

803803
const uniqueURLs = thisStep.URLTargets;
804804
console.log(uniqueURLs)

src/app.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function getTokenBudgetAndMaxAttempts(
215215
if (maxCompletionTokens !== null) {
216216
return {
217217
tokenBudget: maxCompletionTokens,
218-
maxBadAttempts: 2 // Default to medium setting for max attempts
218+
maxBadAttempts: 1 // Default to medium setting for max attempts
219219
};
220220
}
221221

@@ -226,7 +226,7 @@ function getTokenBudgetAndMaxAttempts(
226226
return {tokenBudget: 1000000, maxBadAttempts: 2};
227227
case 'medium':
228228
default:
229-
return {tokenBudget: 500000, maxBadAttempts: 2};
229+
return {tokenBudget: 500000, maxBadAttempts: 1};
230230
}
231231
}
232232

src/types.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,20 @@ export type ErrorAnalysisResponse = {
179179
};
180180

181181

182-
export type SearchResult =
183-
| SearchSnippet
184-
| { title: string; link: string; snippet: string; weight?: number };
182+
export type UnNormalizedSearchSnippet = {
183+
title: string;
184+
url?: string;
185+
description?: string;
186+
link?: string;
187+
snippet?: string;
188+
weight?: number,
189+
date?: string
190+
};
185191

186-
export type SearchSnippet = { title: string; url: string; description: string; weight?: number }
192+
export type SearchSnippet = UnNormalizedSearchSnippet& {
193+
url: string;
194+
description: string;
195+
};
187196

188197
export type BoostedSearchSnippet = SearchSnippet & {
189198
freqBoost: number;

src/utils/url-tools.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {BoostedSearchSnippet, KnowledgeItem, SearchResult, SearchSnippet, TrackerContext, VisitAction} from "../types";
1+
import {BoostedSearchSnippet, KnowledgeItem, SearchSnippet, TrackerContext, VisitAction} from "../types";
22
import {getI18nText, smartMergeStrings} from "./text-tools";
33
import {rerankDocuments} from "../tools/jina-rerank";
44
import {readUrl} from "../tools/read";
@@ -182,7 +182,7 @@ const extractUrlParts = (urlStr: string) => {
182182
};
183183

184184
// Function to count occurrences of hostnames and paths
185-
export const countUrlParts = (urlItems: SearchResult[]) => {
185+
export const countUrlParts = (urlItems: SearchSnippet[]) => {
186186
const hostnameCount: Record<string, number> = {};
187187
const pathPrefixCount: Record<string, number> = {};
188188
let totalUrls = 0;

0 commit comments

Comments
 (0)