Initial commit with translated description

This commit is contained in:
2026-03-29 13:07:16 +08:00
commit e8e25274e5
3 changed files with 73 additions and 0 deletions

28
SKILL.md Normal file
View File

@@ -0,0 +1,28 @@
---
name: google-search
description: "使用Google自定义搜索引擎进行网络搜索。"
---
# Google Search Skill
This skill allows OpenClaw agents to perform web searches via Google's Custom Search API (PSE).
## Setup
1. **Google Cloud Console:** Create a project and enable the "Custom Search API".
2. **API Key:** Generate an API Key.
3. **Search Engine ID (CX):** Create a Programmable Search Engine at [cse.google.com](https://cse.google.com/cse/all), and get your CX ID.
4. **Environment:** Store your credentials in a `.env` file in your workspace:
```
GOOGLE_API_KEY=your_key_here
GOOGLE_CSE_ID=your_cx_id_here
```
## Workflow
... (rest of file)
## Example Usage
```bash
GOOGLE_API_KEY=xxx GOOGLE_CSE_ID=yyy python3 skills/google-search/scripts/search.py "OpenClaw documentation"
```

6
_meta.json Normal file
View File

@@ -0,0 +1,6 @@
{
"ownerId": "kn7ey18zr9mrrcpfc4zwy1brzd80bwjm",
"slug": "google-search",
"version": "1.0.0",
"publishedAt": 1769909754813
}

39
scripts/search.py Normal file
View File

@@ -0,0 +1,39 @@
import sys
import json
import requests
import os
def google_search(query, api_key, cse_id, num_results=5):
url = "https://www.googleapis.com/customsearch/v1"
params = {
'q': query,
'key': api_key,
'cx': cse_id,
'num': num_results
}
response = requests.get(url, params=params)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python google_search.py <query> [num_results]")
sys.exit(1)
query = sys.argv[1]
num_results = int(sys.argv[2]) if len(sys.argv) > 2 else 5
# We will pass these via env vars for security
api_key = os.getenv("GOOGLE_API_KEY")
cse_id = os.getenv("GOOGLE_CSE_ID")
if not api_key or not cse_id:
print("Error: GOOGLE_API_KEY and GOOGLE_CSE_ID must be set in environment.")
sys.exit(1)
try:
results = google_search(query, api_key, cse_id, num_results)
print(json.dumps(results, indent=2))
except Exception as e:
print(f"Error: {str(e)}")
sys.exit(1)