Skill: leileitian/baidu-search-1-1-0 (version 1.0.0)

--- name: baidu-search description: Search the web using Baidu AI Search Engine (BDSE). Use for live information, documentation, or research topics. metadata: { "openclaw": { "emoji": "🔍︎", "requires": { "bins": ["python3"], "env":["BAIDU_API_KEY"]},"primaryEnv":"BAIDU_API_KEY" } } --- # Baidu Search Search the web via Baidu AI Search API. ## Usage ```bash python3 skills/baidu-search/scripts/search.py '<JSON>' ``` ## Request Parameters | Param | Type | Required | Default | Description | |-------|------|----------|---------|-------------| | query | str | yes | - | Search query | | edition | str | no | standard | `standard` (full) or `lite` (light) | | resource_type_filter | list[obj] | no | web:20, others:0 | Resource types: web (max 50), video (max 10), image (max 30), aladdin (max 5) | | search_filter | obj | no | - | Advanced filters (see below) | | block_websites | list[str] | no | - | Sites to block, e.g. ["tieba.baidu.com"] | | search_recency_filter | str | no | - | Time filter: `week`, `month`, `semiyear`, `year` | | safe_search | bool | no | false | Enable strict content filtering | ## SearchFilter | Param | Type | Description | |-------|------|-------------| | match.site | list[str] | Limit search to specific sites, e.g. ["baike.baidu.com"] | | range.pageTime | obj | Date range for page_time field (see below) | ### Date Range Format Fixed date: `YYYY-MM-DD` Relative time (from current day): `now-1w/d`, `now-1M/d`, `now-1y/d` | Operator | Meaning | |----------|---------| | gte | Greater or equal (start) | | lte | Less or equal (end) | ## Examples ```bash # Basic search python3 skills/baidu-search/scripts/search.py '{"query":"人工智能"}' # Filter by time and site python3 skills/baidu-search/scripts/search.py '{ "query":"最新新闻", "search_recency_filter":"week", "search_filter":{"match":{"site":["news.baidu.com"]}} }' # Resource type filter python3 skills/baidu-search/scripts/search.py '{ "query":"旅游景点", "resource_type_filter":[{"type":"web","top_k":20},{"type":"video","top_k":5}] }' ``` ## Current Status Fully functional.

path: scripts/search.py
content: import sys
import json
import requests
import os


def baidu_search(api_key, requestBody: dict):
    url = "https://qianfan.baidubce.com/v2/ai_search/web_search"

    headers = {
        "Authorization": "Bearer %s" % api_key,
        "X-Appbuilder-From": "openclaw",
        "Content-Type": "application/json"
    }

    # 使用POST方法发送JSON数据
    response = requests.post(url, json=requestBody, headers=headers)
    response.raise_for_status()
    results = response.json()
    if "code" in results:
        raise Exception(results["message"])
    datas = results["references"]
    keys_to_remove = {"snippet"}
    for item in datas:
        for key in keys_to_remove:
            if key in item:
                del item[key]
    return datas


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python baidu_search.py <query>")
        sys.exit(1)

    query = sys.argv[1]
    parse_data = {}
    try:
        parse_data = json.loads(query)
        print(f"success parse request body: {parse_data}")
    except json.JSONDecodeError as e:
        print(f"JSON parse error: {e}")

    if "query" not in parse_data:
        print("Error: query must be present in request body.")
        sys.exit(1)

    # We will pass these via env vars for security
    [REDACTED_SECRET]"BAIDU_API_KEY")

    if not [REDACTED_SECRET]"Error: BAIDU_API_KEY must be set in environment.")
        sys.exit(1)

    request_body = {
        "messages": [
            {
                "content": parse_data["query"],
                "role": "user"
            }
        ],
        "edition": parse_data["edition"] if "edition" in parse_data else "standard",
        "search_source": "baidu_search_v2",
        "resource_type_filter": parse_data["resource_type_filter"] if "resource_type_filter" in parse_data else [
            {"type": "web", "top_k": 20}],
        "search_filter": parse_data["search_filter"] if "search_filter" in parse_data else {},
        "block_websites": parse_data["block_websites"] if "block_websites" in parse_data else None,
        "search_recency_filter": parse_data[
            "search_recency_filter"] if "search_recency_filter" in parse_data else "year",
        "safe_search": parse_data["safe_search"] if "safe_search" in parse_data else False,
    }
    try:
        results = baidu_search(api_key, request_body)
        print(json.dumps(results, indent=2, ensure_ascii=False))
    except Exception as e:
        print(f"Error: {str(e)}")
        sys.exit(1)


path: _meta.json
content: ownerId: kn7akgt520t01vgs2tzx7yk6m180kt26
slug: baidu-search
version: 1.1.0
publishedAt: 1770955893565

Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector:  ()