mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-25 22:16:49 +08:00
feat: add meta param to search queries
This commit is contained in:
parent
05f81380a2
commit
c1f8f9525d
19
src/agent.ts
19
src/agent.ts
@ -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);
|
||||
|
||||
22
src/app.ts
22
src/app.ts
@ -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 + ' ';
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -327,6 +327,7 @@ export interface ChatCompletionChunk {
|
||||
content?: string;
|
||||
type?: 'text' | 'think' | 'json' | 'error';
|
||||
url?: string;
|
||||
query?: string;
|
||||
annotations?: Array<URLAnnotation>;
|
||||
};
|
||||
logprobs: null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user