feat: add meta param to search queries

This commit is contained in:
Han Xiao 2025-06-17 18:42:33 -07:00
parent 05f81380a2
commit c1f8f9525d
4 changed files with 41 additions and 5 deletions

View File

@ -18,7 +18,8 @@ import {
BoostedSearchSnippet,
SearchSnippet, EvaluationResponse, Reference, SERPQuery, RepeatEvaluationType, UnNormalizedSearchSnippet, WebContent,
ImageObject,
ImageReference
ImageReference,
SearchAction
} from "./types";
import { TrackerContext } from "./types";
import { search } from "./tools/jina-search";
@ -281,7 +282,8 @@ async function executeSearchQueries(
SchemaGen: Schemas,
webContents: Record<string, WebContent>,
onlyHostnames?: string[],
searchProvider?: string
searchProvider?: string,
meta?: string
): Promise<{
newKnowledge: KnowledgeItem[],
searchedQueries: string[]
@ -303,7 +305,7 @@ async function executeSearchQueries(
switch (searchProvider || SEARCH_PROVIDER) {
case 'jina':
case 'arxiv':
results = (await search(query, searchProvider, 30, context.tokenTracker)).response.results || [];
results = (await search(query, searchProvider, 30, meta, context.tokenTracker)).response.results || [];
break;
case 'duck':
results = (await duckSearch(query.q, { safeSearch: SafeSearchType.STRICT })).results;
@ -380,6 +382,14 @@ async function executeSearchQueries(
type: 'side-info',
updated: query.tbs ? formatDateRange(query) : undefined
});
} finally {
context.actionTracker.trackAction({
thisStep: {
action: 'search',
think: '',
searchRequests: [oldQuery]
} as SearchAction
})
}
@ -802,7 +812,8 @@ But then you realized you have asked them before. You decided to to think out of
SchemaGen,
allWebContents,
undefined,
searchProvider
searchProvider,
'more'
);
allKeywords.push(...searchedQueries);

View File

@ -8,6 +8,7 @@ import {
ChatCompletionChunk,
AnswerAction,
Model, StepAction, VisitAction,
SearchAction,
} from './types';
import { TokenTracker } from "./utils/token-tracker";
import { ActionTracker } from "./utils/action-tracker";
@ -561,6 +562,27 @@ app.post('/v1/chat/completions', validationRules, (async (req: Request, res: Res
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
});
}
if (step.action === 'search') {
// emit every search request in the search action in url field
((step as SearchAction).searchRequests as string[])?.forEach((query) => {
const chunk: ChatCompletionChunk = {
id: requestId,
object: 'chat.completion.chunk',
created,
model: body.model,
system_fingerprint: 'fp_' + requestId,
choices: [{
index: 0,
delta: { type: 'think', query },
logprobs: null,
finish_reason: null,
}]
};
res.write(`data: ${JSON.stringify(chunk)}\n\n`);
});
}
if (step.think) {
// if not ends with a space, add one
const content = step.think + ' ';

View File

@ -8,6 +8,7 @@ export async function search(
query: SERPQuery,
domain?: string,
num?: number,
meta?: string,
tracker?: TokenTracker
): Promise<{ response: JinaSearchResponse }> {
try {
@ -20,7 +21,8 @@ export async function search(
{
...query,
domain,
num
num,
meta
},
{
headers: {

View File

@ -327,6 +327,7 @@ export interface ChatCompletionChunk {
content?: string;
type?: 'text' | 'think' | 'json' | 'error';
url?: string;
query?: string;
annotations?: Array<URLAnnotation>;
};
logprobs: null;