mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-06-02 00:57:41 +08:00
feat: key management and scheduled task tools
This commit is contained in:
91
skills/bocha-search/SKILL.md
Normal file
91
skills/bocha-search/SKILL.md
Normal file
@@ -0,0 +1,91 @@
|
||||
---
|
||||
name: bocha-search
|
||||
description: High-quality web search with AI-optimized results. Use when user needs to search the internet for current information, news, or research topics.
|
||||
homepage: https://open.bocha.cn/
|
||||
metadata:
|
||||
emoji: 🔍
|
||||
requires:
|
||||
bins: ["curl"]
|
||||
env: ["BOCHA_API_KEY"]
|
||||
primaryEnv: "BOCHA_API_KEY"
|
||||
---
|
||||
|
||||
# Bocha Search
|
||||
|
||||
High-quality web search powered by Bocha AI, optimized for AI consumption. Returns web pages, images, and detailed metadata.
|
||||
|
||||
## Setup
|
||||
|
||||
This skill requires a Bocha API key. If not configured:
|
||||
|
||||
1. Visit https://open.bocha.cn to get an API key
|
||||
2. Set the key using: `env_config(action="set", key="BOCHA_API_KEY", value="your-key")`
|
||||
3. Or manually add to `~/cow/.env`: `BOCHA_API_KEY=your-key`
|
||||
|
||||
## Usage
|
||||
|
||||
**Important**: Scripts are located relative to this skill's base directory.
|
||||
|
||||
When you see this skill in `<available_skills>`, note the `<base_dir>` path.
|
||||
|
||||
```bash
|
||||
# General pattern:
|
||||
bash "<base_dir>/scripts/search.sh" "<query>" [count] [freshness] [summary]
|
||||
|
||||
# Parameters:
|
||||
# - query: Search query (required)
|
||||
# - count: Number of results (1-50, default: 10)
|
||||
# - freshness: Time range filter (default: noLimit)
|
||||
# Options: noLimit, oneDay, oneWeek, oneMonth, oneYear, YYYY-MM-DD..YYYY-MM-DD
|
||||
# - summary: Include text summary (true/false, default: false)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Basic search
|
||||
```bash
|
||||
bash "<base_dir>/scripts/search.sh" "latest AI news"
|
||||
```
|
||||
|
||||
### Search with more results
|
||||
```bash
|
||||
bash "<base_dir>/scripts/search.sh" "Python tutorials" 20
|
||||
```
|
||||
|
||||
### Search recent content with summary
|
||||
```bash
|
||||
bash "<base_dir>/scripts/search.sh" "阿里巴巴ESG报告" 10 oneWeek true
|
||||
```
|
||||
|
||||
### Search specific date range
|
||||
```bash
|
||||
bash "<base_dir>/scripts/search.sh" "tech news" 15 "2025-01-01..2025-02-01"
|
||||
```
|
||||
|
||||
## Response Format
|
||||
|
||||
The API returns structured data compatible with Bing Search API:
|
||||
|
||||
**Web Pages** (in `data.webPages.value`):
|
||||
- `name`: Page title
|
||||
- `url`: Page URL
|
||||
- `snippet`: Short description
|
||||
- `summary`: Full text summary (if requested)
|
||||
- `siteName`: Website name
|
||||
- `siteIcon`: Website icon URL
|
||||
- `datePublished`: Publication date (UTC+8)
|
||||
- `language`: Page language
|
||||
|
||||
**Images** (in `data.images.value`):
|
||||
- `contentUrl`: Image URL
|
||||
- `hostPageUrl`: Source page URL
|
||||
- `width`, `height`: Image dimensions
|
||||
- `thumbnailUrl`: Thumbnail URL
|
||||
|
||||
## Notes
|
||||
|
||||
- **Optimized for AI**: Results include summaries and structured metadata
|
||||
- **Time range**: Use `noLimit` for best results (algorithm auto-optimizes time range)
|
||||
- **Timeout**: 30 seconds
|
||||
- **Rate limits**: Check your API plan at https://open.bocha.cn
|
||||
- **Response format**: Compatible with Bing Search API for easy integration
|
||||
75
skills/bocha-search/scripts/search.sh
Executable file
75
skills/bocha-search/scripts/search.sh
Executable file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
# Bocha Web Search API wrapper
|
||||
# API Docs: https://open.bocha.cn/
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
query="${1:-}"
|
||||
count="${2:-10}"
|
||||
freshness="${3:-noLimit}"
|
||||
summary="${4:-false}"
|
||||
|
||||
if [ -z "$query" ]; then
|
||||
echo '{"error": "Query is required", "usage": "bash search.sh <query> [count] [freshness] [summary]"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "${BOCHA_API_KEY:-}" ]; then
|
||||
echo '{"error": "BOCHA_API_KEY environment variable is not set", "help": "Visit https://open.bocha.cn to get an API key"}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate count (1-50)
|
||||
if ! [[ "$count" =~ ^[0-9]+$ ]] || [ "$count" -lt 1 ] || [ "$count" -gt 50 ]; then
|
||||
count=10
|
||||
fi
|
||||
|
||||
# Build JSON request body
|
||||
request_body=$(cat <<EOF
|
||||
{
|
||||
"query": "$query",
|
||||
"count": $count,
|
||||
"freshness": "$freshness",
|
||||
"summary": $summary
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# Call Bocha API
|
||||
response=$(curl -sS --max-time 30 \
|
||||
-X POST \
|
||||
-H "Authorization: Bearer $BOCHA_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Accept: application/json" \
|
||||
-d "$request_body" \
|
||||
"https://api.bocha.cn/v1/web-search" 2>&1)
|
||||
|
||||
curl_exit_code=$?
|
||||
|
||||
if [ $curl_exit_code -ne 0 ]; then
|
||||
echo "{\"error\": \"Failed to call Bocha API\", \"details\": \"$response\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Simple JSON validation - check if response starts with { or [
|
||||
if [[ ! "$response" =~ ^[[:space:]]*[\{\[] ]]; then
|
||||
echo "{\"error\": \"Invalid JSON response from API\", \"response\": \"$response\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract API code using grep and sed (basic JSON parsing)
|
||||
api_code=$(echo "$response" | grep -o '"code"[[:space:]]*:[[:space:]]*[0-9]*' | grep -o '[0-9]*' | head -1)
|
||||
|
||||
# If code extraction failed or code is not 200, check for error
|
||||
if [ -n "$api_code" ] && [ "$api_code" != "200" ]; then
|
||||
# Try to extract error message
|
||||
api_msg=$(echo "$response" | grep -o '"msg"[[:space:]]*:[[:space:]]*"[^"]*"' | sed 's/"msg"[[:space:]]*:[[:space:]]*"\(.*\)"/\1/' | head -1)
|
||||
if [ -z "$api_msg" ]; then
|
||||
api_msg="Unknown error"
|
||||
fi
|
||||
echo "{\"error\": \"API returned error\", \"code\": $api_code, \"message\": \"$api_msg\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Return the full response
|
||||
echo "$response"
|
||||
Reference in New Issue
Block a user