mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:28:56 +08:00
refactor: query rewriter
This commit is contained in:
parent
6cc48d07fd
commit
53cb3a4318
@ -1,42 +1,46 @@
|
||||
import axios from 'axios';
|
||||
import { SERPER_API_KEY } from "../config";
|
||||
import {SERPER_API_KEY} from "../config";
|
||||
|
||||
import {SerperSearchResponse, SERPQuery} from '../types';
|
||||
|
||||
|
||||
export async function serperSearch(query: SERPQuery): Promise<{ response: SerperSearchResponse }> {
|
||||
const response = await axios.post<SerperSearchResponse>('https://google.serper.dev/search', {
|
||||
...query,
|
||||
autocorrect: false,
|
||||
}, {
|
||||
headers: {
|
||||
'X-API-KEY': SERPER_API_KEY,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
const response = await axios.post<SerperSearchResponse>('https://google.serper.dev/search', {
|
||||
...query,
|
||||
autocorrect: false,
|
||||
}, {
|
||||
headers: {
|
||||
'X-API-KEY': SERPER_API_KEY,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
// Maintain the same return structure as the original code
|
||||
return { response: response.data };
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Serper search failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
// Maintain the same return structure as the original code
|
||||
return {response: response.data};
|
||||
}
|
||||
|
||||
|
||||
export async function serperSearchOld(query: string): Promise<{ response: SerperSearchResponse }> {
|
||||
const response = await axios.post<SerperSearchResponse>('https://google.serper.dev/search', {
|
||||
q: query,
|
||||
autocorrect: false,
|
||||
}, {
|
||||
headers: {
|
||||
'X-API-KEY': SERPER_API_KEY,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
const response = await axios.post<SerperSearchResponse>('https://google.serper.dev/search', {
|
||||
q: query,
|
||||
autocorrect: false,
|
||||
}, {
|
||||
headers: {
|
||||
'X-API-KEY': SERPER_API_KEY,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 10000
|
||||
});
|
||||
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Serper search failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Serper search failed: ${response.status} ${response.statusText}`)
|
||||
}
|
||||
|
||||
// Maintain the same return structure as the original code
|
||||
return { response: response.data };
|
||||
// Maintain the same return structure as the original code
|
||||
return {response: response.data};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user