feat: add searchProvider param to executeSearchQueries and getResponse

This commit is contained in:
Han Xiao 2025-06-09 14:31:53 -07:00
parent d5a31bce52
commit 9fa0fe3b22
3 changed files with 58 additions and 37 deletions

View File

@ -276,7 +276,8 @@ async function executeSearchQueries(
allURLs: Record<string, SearchSnippet>, allURLs: Record<string, SearchSnippet>,
SchemaGen: Schemas, SchemaGen: Schemas,
webContents: Record<string, WebContent>, webContents: Record<string, WebContent>,
onlyHostnames?: string[] onlyHostnames?: string[],
searchProvider?: string
): Promise<{ ): Promise<{
newKnowledge: KnowledgeItem[], newKnowledge: KnowledgeItem[],
searchedQueries: string[] searchedQueries: string[]
@ -295,7 +296,7 @@ async function executeSearchQueries(
try { try {
console.log('Search query:', query); console.log('Search query:', query);
switch (SEARCH_PROVIDER) { switch (searchProvider || SEARCH_PROVIDER) {
case 'jina': case 'jina':
results = (await search(query, context.tokenTracker)).response?.data || []; results = (await search(query, context.tokenTracker)).response?.data || [];
break; break;
@ -392,7 +393,8 @@ export async function getResponse(question?: string,
onlyHostnames: string[] = [], onlyHostnames: string[] = [],
maxRef: number = 10, maxRef: number = 10,
minRelScore: number = 0.75, minRelScore: number = 0.75,
languageCode: string | undefined = undefined languageCode: string | undefined = undefined,
searchProvider?: string
): Promise<{ result: StepAction; context: TrackerContext; visitedURLs: string[], readURLs: string[], allURLs: string[] }> { ): Promise<{ result: StepAction; context: TrackerContext; visitedURLs: string[], readURLs: string[], allURLs: string[] }> {
let step = 0; let step = 0;
@ -765,7 +767,9 @@ But then you realized you have asked them before. You decided to to think out of
context, context,
allURLs, allURLs,
SchemaGen, SchemaGen,
allWebContents allWebContents,
undefined,
searchProvider
); );
allKeywords.push(...searchedQueries); allKeywords.push(...searchedQueries);
@ -794,7 +798,8 @@ But then you realized you have asked them before. You decided to to think out of
allURLs, allURLs,
SchemaGen, SchemaGen,
allWebContents, allWebContents,
onlyHostnames onlyHostnames,
searchProvider
); );
if (searchedQueries.length > 0) { if (searchedQueries.length > 0) {

View File

@ -263,7 +263,14 @@ app.get('/v1/models', (async (_req: Request, res: Response) => {
object: 'model', object: 'model',
created: 1686935002, created: 1686935002,
owned_by: 'jina-ai' owned_by: 'jina-ai'
}]; },
{
id: 'jina-deepsearch-v2',
object: 'model',
created: 1717987200,
owned_by: 'jina-ai'
}
];
res.json({ res.json({
object: 'list', object: 'list',
@ -281,6 +288,13 @@ app.get('/v1/models/:model', (async (req: Request, res: Response) => {
created: 1686935002, created: 1686935002,
owned_by: 'jina-ai' owned_by: 'jina-ai'
}); });
} else if (modelId === 'jina-deepsearch-v2') {
res.json({
id: 'jina-deepsearch-v2',
object: 'model',
created: 1717987200,
owned_by: 'jina-ai'
});
} else { } else {
res.status(404).json({ res.status(404).json({
error: { error: {
@ -567,7 +581,8 @@ app.post('/v1/chat/completions', (async (req: Request, res: Response) => {
body.only_hostnames?.map(i => normalizeHostName(i)), body.only_hostnames?.map(i => normalizeHostName(i)),
body.max_annotations, body.max_annotations,
body.min_annotation_relevance, body.min_annotation_relevance,
body.language_code body.language_code,
body.search_provider
) )
let finalAnswer = (finalStep as AnswerAction).mdAnswer; let finalAnswer = (finalStep as AnswerAction).mdAnswer;

View File

@ -260,6 +260,7 @@ export interface ChatCompletionRequest {
max_annotations?: number; max_annotations?: number;
min_annotation_relevance?: number; min_annotation_relevance?: number;
language_code?: string; language_code?: string;
search_provider?: string;
} }
export interface URLAnnotation { export interface URLAnnotation {