|
1 | | -import Exa, {SearchResult} from "exa-js"; |
| 1 | +import Exa, {RegularSearchOptions, SearchResult} from "exa-js"; |
2 | 2 | const exa = new Exa(process.env.EXA_API_KEY); |
3 | 3 |
|
4 | | -export async function getSearchResults(queries: string[], linksPerQuery: number = 5): Promise<SearchResult[]> { |
| 4 | +export async function getSearchResults(queries: string[], options?: RegularSearchOptions): Promise<SearchResult[]> { |
5 | 5 | let results: SearchResult[] = []; |
6 | 6 | for (const query of queries) { |
7 | 7 | const searchResponse = await exa.searchAndContents(query, { |
8 | | - numResults: linksPerQuery, |
9 | | - useAutoprompt: false, |
| 8 | + numResults: options?.numResults ?? 5, |
| 9 | + useAutoprompt: options?.useAutoprompt ?? false, |
| 10 | + ...options, |
10 | 11 | }); |
11 | 12 | results.push(...searchResponse.results); |
12 | 13 | } |
13 | 14 | return results; |
14 | 15 | } |
| 16 | + |
| 17 | +export async function getSearchResultsByDomain(domain: string, queries: string[], options?: RegularSearchOptions): Promise<SearchResult[]> { |
| 18 | + let results: SearchResult[] = []; |
| 19 | + for (const query of queries) { |
| 20 | + const searchResponse = await exa.searchAndContents(query, { |
| 21 | + numResults: options?.numResults ?? 5, |
| 22 | + useAutoprompt: options?.useAutoprompt ?? false, |
| 23 | + includeDomains: [domain], |
| 24 | + ...options, |
| 25 | + }); |
| 26 | + results.push(...searchResponse.results); |
| 27 | + } |
| 28 | + return results; |
| 29 | +} |
| 30 | + |
| 31 | +export async function getSearchResultsByUrl(url: string, linksPerQuery: number = 5): Promise<SearchResult[]> { |
| 32 | + let results: SearchResult[] = []; |
| 33 | + const searchResponse = await exa.findSimilarAndContents(url, { |
| 34 | + numResults: linksPerQuery, |
| 35 | + }); |
| 36 | + results.push(...searchResponse.results); |
| 37 | + return results; |
| 38 | +} |
0 commit comments