UNPKG

@lobehub/chat

Version:

Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.

34 lines (26 loc) 788 B
import qs from 'query-string'; import urlJoin from 'url-join'; import { SearchResponse } from '@/types/tool/search'; export class SearXNGClient { private baseUrl: string; constructor(baseUrl: string) { this.baseUrl = baseUrl; } async search(query: string, engines?: string[]): Promise<SearchResponse> { try { const searchParams = qs.stringify({ engines: engines?.join(','), format: 'json', q: query, }); const response = await fetch(urlJoin(this.baseUrl, `/search?${searchParams}`)); if (response.ok) { return await response.json(); } throw new Error(`Failed to search: ${response.statusText}`); } catch (error) { console.error('Error searching:', error); throw error; } } }