add doc for web search
This commit is contained in:
parent
5eec153fc0
commit
ea48c7f3a2
|
|
@ -38,6 +38,7 @@ We model the LLM workflow as a **Graph + Shared Store**:
|
||||||
- [LLM Wrapper](./utility_function/llm.md)
|
- [LLM Wrapper](./utility_function/llm.md)
|
||||||
- [Tool](./utility_function/tool.md)
|
- [Tool](./utility_function/tool.md)
|
||||||
- [(Optional) Viz and Debug](./utility_function/viz.md)
|
- [(Optional) Viz and Debug](./utility_function/viz.md)
|
||||||
|
- [(Optional) Web Search](./utility_function/websearch.md)
|
||||||
- Chunking
|
- Chunking
|
||||||
|
|
||||||
> We do not provide built-in utility functions. Example implementations are provided as reference.
|
> We do not provide built-in utility functions. Example implementations are provided as reference.
|
||||||
|
|
|
||||||
|
|
@ -156,24 +156,8 @@ def crawl_web(url):
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 7. Basic Search (SerpAPI example)
|
|
||||||
|
|
||||||
```python
|
## 7. Audio Transcription (OpenAI Whisper)
|
||||||
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)
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def transcribe_audio(file_path):
|
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
|
```python
|
||||||
def text_to_speech(text):
|
def text_to_speech(text):
|
||||||
|
|
@ -197,7 +181,7 @@ def text_to_speech(text):
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 10. Sending Email
|
## 9. Sending Email
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def send_email(to_address, subject, body, from_address, password):
|
def send_email(to_address, subject, body, from_address, password):
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue