-
Notifications
You must be signed in to change notification settings - Fork 0
Add SearchApi to search #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
503e83e
1355bd7
a1861f6
151116a
598fbd5
9874ef0
43f0794
29eb962
ba3c49a
af2d80b
1a30dda
1144c4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Self-hosting Firecrawl | ||
|
|
||
| # Self-hosting Firecrawl | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GPT summary of 2fa877 - f6510c:
|
||
| #### Contributor? | ||
|
|
||
| Welcome to [Firecrawl](https://firecrawl.dev) 🔥! Here are some instructions on how to get the project locally so you can run it on your own and contribute. | ||
|
|
@@ -176,4 +176,4 @@ By addressing these common issues, you can ensure a smoother setup and operation | |
|
|
||
| ## Install Firecrawl on a Kubernetes Cluster (Simple Version) | ||
|
|
||
| Read the [examples/kubernetes-cluster-install/README.md](https://github.com/mendableai/firecrawl/blob/main/examples/kubernetes-cluster-install/README.md) for instructions on how to install Firecrawl on a Kubernetes Cluster. | ||
| Read the [examples/kubernetes-cluster-install/README.md](https://github.com/mendableai/firecrawl/blob/main/examples/kubernetes-cluster-install/README.md) for instructions on how to install Firecrawl on a Kubernetes Cluster. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # ===== Required ENVS ====== | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| NUM_WORKERS_PER_QUEUE=8 | ||
| NUM_WORKERS_PER_QUEUE=8 | ||
| PORT=3002 | ||
| HOST=0.0.0.0 | ||
| REDIS_URL=redis://redis:6379 #for self-hosting using docker, use redis://redis:6379. For running locally, use redis://localhost:6379 | ||
|
|
@@ -11,9 +11,14 @@ USE_DB_AUTHENTICATION=true | |
|
|
||
| # ===== Optional ENVS ====== | ||
|
|
||
| # SearchApi key. Head to https://searchapi.com/ to get your API key | ||
| SEARCHAPI_API_KEY= | ||
| # SearchApi engine, defaults to google. Available options: google, bing, baidu, google_news, etc. Head to https://searchapi.com/ to explore more engines | ||
| SEARCHAPI_ENGINE= | ||
|
|
||
| # Supabase Setup (used to support DB authentication, advanced logging, etc.) | ||
| SUPABASE_ANON_TOKEN= | ||
| SUPABASE_URL= | ||
| SUPABASE_ANON_TOKEN= | ||
| SUPABASE_URL= | ||
| SUPABASE_SERVICE_TOKEN= | ||
|
|
||
| # Other Optionals | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,4 +12,4 @@ ANTHROPIC_API_KEY= | |
| BULL_AUTH_KEY= | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| LOGTAIL_KEY= | ||
| PLAYWRIGHT_MICROSERVICE_URL= | ||
|
|
||
| SEARCHAPI_API_KEY= | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { Logger } from "../../src/lib/logger"; | |
| import { SearchResult } from "../../src/lib/entities"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| import { googleSearch } from "./googlesearch"; | ||
| import { fireEngineMap } from "./fireEngine"; | ||
| import { searchapi_search } from "./searchapi"; | ||
| import { serper_search } from "./serper"; | ||
|
|
||
| export async function search({ | ||
|
|
@@ -30,7 +31,16 @@ export async function search({ | |
| timeout?: number; | ||
| }): Promise<SearchResult[]> { | ||
| try { | ||
|
|
||
| if (process.env.SEARCHAPI_API_KEY) { | ||
| return await searchapi_search(query, { | ||
| num_results, | ||
| tbs, | ||
| filter, | ||
| lang, | ||
| country, | ||
| location | ||
| }); | ||
| } | ||
| if (process.env.SERPER_API_KEY) { | ||
| return await serper_search(query, { | ||
| num_results, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import axios from "axios"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| import dotenv from "dotenv"; | ||
| import { SearchResult } from "../../src/lib/entities"; | ||
|
|
||
| dotenv.config(); | ||
|
|
||
| interface SearchOptions { | ||
| tbs?: string; | ||
| filter?: string; | ||
| lang?: string; | ||
| country?: string; | ||
| location?: string; | ||
| num_results: number; | ||
| page?: number; | ||
| } | ||
|
|
||
| export async function searchapi_search(q: string, options: SearchOptions): Promise<SearchResult[]> { | ||
| const params = { | ||
| q: q, | ||
| hl: options.lang, | ||
| gl: options.country, | ||
| location: options.location, | ||
| num: options.num_results, | ||
| page: options.page ?? 1, | ||
| engine: process.env.SEARCHAPI_ENGINE || "google", | ||
| }; | ||
|
|
||
| const url = `https://www.searchapi.io/api/v1/search`; | ||
|
|
||
| try { | ||
| const response = await axios.get(url, { | ||
| headers: { | ||
| "Authorization": `Bearer ${process.env.SEARCHAPI_API_KEY}`, | ||
| "Content-Type": "application/json", | ||
| "X-SearchApi-Source": "Firecrawl", | ||
| }, | ||
| params: params, | ||
| }); | ||
|
|
||
|
|
||
| if (response.status === 401) { | ||
| throw new Error("Unauthorized. Please check your API key."); | ||
| } | ||
|
|
||
| const data = response.data; | ||
|
|
||
| if (data && Array.isArray(data.organic_results)) { | ||
| return data.organic_results.map((a: any) => ({ | ||
| url: a.link, | ||
| title: a.title, | ||
| description: a.snippet, | ||
| })); | ||
| } else { | ||
| return []; | ||
| } | ||
| } catch (error) { | ||
| console.error(`There was an error searching for content: ${error.message}`); | ||
| return []; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of 96878e - f2460b:
Error: couldn't generate summary