mirror of
https://github.com/jina-ai/node-DeepResearch.git
synced 2025-12-26 06:27:28 +08:00
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { SERPER_API_KEY } from "../config";
|
|
import axiosClient from "../utils/axios-client";
|
|
|
|
import { SerperSearchResponse, SERPQuery } from '../types';
|
|
|
|
|
|
export async function serperSearch(query: SERPQuery): Promise<{ response: SerperSearchResponse }> {
|
|
const response = await axiosClient.post<SerperSearchResponse>('https://google.serper.dev/search', {
|
|
...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}`)
|
|
}
|
|
|
|
// 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 axiosClient.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}`)
|
|
}
|
|
|
|
// Maintain the same return structure as the original code
|
|
return { response: response.data };
|
|
}
|