diff --git a/docs/index.md b/docs/index.md index 7e71b01..e0ac2e8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -38,6 +38,7 @@ We model the LLM workflow as a **Graph + Shared Store**: - [LLM Wrapper](./utility_function/llm.md) - [Tool](./utility_function/tool.md) - [(Optional) Viz and Debug](./utility_function/viz.md) +- [(Optional) Web Search](./utility_function/websearch.md) - Chunking > We do not provide built-in utility functions. Example implementations are provided as reference. diff --git a/docs/utility_function/tool.md b/docs/utility_function/tool.md index 20664b8..bf50466 100644 --- a/docs/utility_function/tool.md +++ b/docs/utility_function/tool.md @@ -156,24 +156,8 @@ def crawl_web(url): --- -## 7. Basic Search (SerpAPI example) -```python -def search_google(query): - import requests - params = { - "engine": "google", - "q": query, - "api_key": "YOUR_API_KEY" - } - r = requests.get("https://serpapi.com/search", params=params) - return r.json() -``` - ---- - - -## 8. Audio Transcription (OpenAI Whisper) +## 7. Audio Transcription (OpenAI Whisper) ```python def transcribe_audio(file_path): @@ -185,7 +169,7 @@ def transcribe_audio(file_path): --- -## 9. Text-to-Speech (TTS) +## 8. Text-to-Speech (TTS) ```python def text_to_speech(text): @@ -197,7 +181,7 @@ def text_to_speech(text): --- -## 10. Sending Email +## 9. Sending Email ```python def send_email(to_address, subject, body, from_address, password): diff --git a/docs/utility_function/websearch.md b/docs/utility_function/websearch.md new file mode 100644 index 0000000..e140250 --- /dev/null +++ b/docs/utility_function/websearch.md @@ -0,0 +1,113 @@ +--- +layout: default +title: "Tool" +parent: "Utility Function" +nav_order: 4 +--- +## Tool + +We recommend some implementations of commonly used web search tools. + +| **API** | **Free Tier** | **Pricing Model** | **Official API Page** | +|---------------------------------|-----------------------------------------------|-----------------------------------------------------------------|------------------------------------------------------------------------| +| **Google Custom Search JSON API** | 100 queries/day free | $5 per 1000 queries. | [Link](https://developers.google.com/custom-search/v1/overview) | +| **Bing Web Search API** | 1,000 queries/month | $15–$25 per 1,000 queries. | [Link](https://azure.microsoft.com/en-us/services/cognitive-services/bing-web-search-api/) | +| **DuckDuckGo Instant Answer** | Completely free (Instant Answers only, **no URLs**) | No paid plans; usage unlimited, but data is limited | [Link](https://duckduckgo.com/api) | +| **Brave Search API** | 2,000 queries/month free | $3 per 1k queries for Base, $5 per 1k for Pro | [Link](https://brave.com/search/api/) | +| **SerpApi** | 100 searches/month free | Start at $75/month for 5,000 searches| [Link](https://serpapi.com/) | +| **RapidAPI** | Many options | Many options | [Link](https://rapidapi.com/search?term=search&sortBy=ByRelevance) | + +## Example Python Code Samples + +### 1. Google Custom Search JSON API +```python +import requests + +API_KEY = "YOUR_API_KEY" +CX_ID = "YOUR_CX_ID" +query = "example" + +url = "https://www.googleapis.com/customsearch/v1" +params = { + "key": API_KEY, + "cx": CX_ID, + "q": query +} + +response = requests.get(url, params=params) +results = response.json() +print(results) +``` + +### 2. Bing Web Search API +```python +import requests + +SUBSCRIPTION_KEY = "YOUR_BING_API_KEY" +query = "example" + +url = "https://api.bing.microsoft.com/v7.0/search" +headers = {"Ocp-Apim-Subscription-Key": SUBSCRIPTION_KEY} +params = {"q": query} + +response = requests.get(url, headers=headers, params=params) +results = response.json() +print(results) +``` + +### 3. DuckDuckGo Instant Answer +```python +import requests + +query = "example" +url = "https://api.duckduckgo.com/" +params = { + "q": query, + "format": "json" +} + +response = requests.get(url, params=params) +results = response.json() +print(results) +``` + +### 4. Brave Search API +```python +import requests + +SUBSCRIPTION_TOKEN = "YOUR_BRAVE_API_TOKEN" +query = "example" + +url = "https://api.search.brave.com/res/v1/web/search" +headers = { + "X-Subscription-Token": SUBSCRIPTION_TOKEN +} +params = { + "q": query +} + +response = requests.get(url, headers=headers, params=params) +results = response.json() +print(results) +``` + +### 5. SerpApi +```python +import requests + +API_KEY = "YOUR_SERPAPI_KEY" +query = "example" + +url = "https://serpapi.com/search" +params = { + "engine": "google", + "q": query, + "api_key": API_KEY +} + +response = requests.get(url, params=params) +results = response.json() +print(results) +``` + +