add doc for web search

This commit is contained in:
zachary62 2025-03-05 18:10:28 -05:00
parent 5eec153fc0
commit ea48c7f3a2
3 changed files with 117 additions and 19 deletions

View File

@ -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.

View File

@ -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):

View File

@ -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)
```