利用浏览器自动化(Chrome Relay)及可选的Hugging Face API,调用外部AI模型(如ChatGPT、Claude、Hugging Face等)作为工具。适用于...
外部 AI 集成 技能是一项面向实际任务的技能,主要用于此技能提供了将外部 AI 模型用作工具的模式, 助手可以调用;它扩展了已有的浏览器 {自动操作 和 API}/integrati。
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;
若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
该技能提供了一系列模式,用于将外部 AI 模型作为工具按需调用。它扩展了现有的浏览器自动化与 API 集成技能,使助手能够:
使用 Chrome Relay 自动化访问 ChatGPT、Claude、Gemini 或任何需要浏览器界面的 Web 端 LLM。
前提条件:
chatgpt.com、claude.ai)已完成登录(存在有效会话 Cookie)。memory/patterns/playbooks.md 中的 “Browser Automation (Chrome Relay)”)。操作步骤:
profile="chrome")。refs="aria" 获取稳定 DOM 引用)。示例工作流:
# 此为概念性示例;实际实现使用浏览器工具调用。
def ask_chatgpt(prompt):
# 1. 确保 Chrome Relay 已连接
browser(action="open", profile="chrome", targetUrl="https://chatgpt.com")
# 2. 执行快照以获取引用
snap = browser(action="snapshot", refs="aria")
# 3. 查找输入框(aria role="textbox")和发送按钮
input_ref = snap.find_element(role="textbox", name="Message")
send_ref = snap.find_element(role="button", name="Send")
# 4. 输入提示词并点击发送
browser(action="act", request={"kind":"type", "ref":input_ref, "text":prompt})
browser(action="act", request={"kind":"click", "ref":send_ref})
# 5. 等待响应(简化处理)
time.sleep(10)
# 6. 再次执行快照,从最后一条消息气泡中提取响应
snap2 = browser(action="snapshot", refs="aria")
response_element = snap2.find_last_message()
return response_element.text
关键注意事项:
对于托管在 Hugging Face Spaces 或 Hugging Face 推理 API 上的模型,可直接通过 HTTP 请求调用。
前提条件:
"gpt2"、"google/flan-t5-large"、"microsoft/DialoGPT-medium")。操作步骤:
~/.huggingface/token)。curl 或 exec 调用 Python requests 模块。示例脚本(使用 curl):
#!/bin/bash
set -e
MODEL="google/flan-t5-large"
PROMPT="Translate English to German: How are you?"
API_TOKEN=$(op read "op://Personal/HuggingFace/api_token")
curl -s "https://api-inference.huggingface.co/models/$MODEL"
-H "Authorization: Bearer $API_TOKEN"
-H "Content-Type: application/json"
-d "{"inputs": "$PROMPT"}" | jq -r '.[0].generated_text'
示例 Python 函数(使用 requests):
import requests
import os
def hf_inference(model, inputs, parameters=None):
api_token = os.getenv("HF_TOKEN") # 或通过 1Password 获取
url = f"https://api-inference.huggingface.co/models/{model}"
headers = {"Authorization": f"Bearer {api_token}"}
payload = {"inputs": inputs}
if parameters:
payload.update(parameters)
resp = requests.post(url, headers=headers, json=payload)
resp.raise_for_status()
return resp.json()
关键注意事项:
{"options":{"wait_for_model":true}}。不启动子代理,而是在助手自身的推理流程中直接调用外部 AI。
模式:
示例决策逻辑:
def external_ai_assist(task_type, prompt):
if task_type == "code_review":
# 通过浏览器自动化调用 Claude
return ask_claude(prompt)
elif task_type == "translation":
# 使用 Hugging Face 翻译模型
return hf_inference("Helsinki-NLP/opus-mt-en-de", prompt)
elif task_type == "creative_writing":
# 通过浏览器自动化调用 ChatGPT
return ask_chatgpt(prompt)
else:
raise ValueError(f"未为 {task_type} 配置外部 AI")
外部模型所需的提示风格可能与其原生模型不同。
"Translate English to German: ...")。代码审查提示示例:
You are an expert software engineer reviewing the following code snippet. Please:
1. Identify potential bugs or security issues.
2. Suggest performance improvements.
3. Comment on code style and readability.
4. Output your review as a JSON with keys "bugs", "performance", "style".
Code:
```python
def calculate_average(numbers):
total = 0
for n in numbers:
total += n
return total / len(numbers)
```
外部服务可能失败;需设计优雅降级策略。
memory/YYYY‑MM‑DD.md,并添加标签 external‑ai‑failure,便于后续分析。示例备用结构:
try:
response = ask_chatgpt(prompt)
except (BrowserError, TimeoutError) as e:
log_failure("ChatGPT", e)
# 切换至 Hugging Face
response = hf_inference("google/flan-t5-xxl", prompt)
except Exception as e:
log_failure("All external AI", e)
response = None
if response:
integrate(response)
else:
# 继续由助手自身完成推理
pass
场景:助手被要求审查一个复杂的 React 组件。它通过 Chrome Relay 调用 Claude,获取详细的第二意见。
步骤:
ask_claude(prompt)(基于浏览器自动化)。场景:用户提供一段英文段落,要求翻译为德语。助手调用 Hugging Face 翻译模型。
步骤:
"Translate English to German: " 。hf_inference("Helsinki-NLP/opus-mt-en-de", prompt)。场景:用户需要一篇关于 AI 助手的博客文章标题建议。助手调用 ChatGPT 生成 10 个选项。
步骤:
场景:用户请求对某项商业决策进行战略分析。助手先自行完成分析,再向 ChatGPT 提问以识别潜在盲点。
步骤:
docs/browser-automation.md — Chrome Relay 的安装与命令说明。skills/huggingface/SKILL.md — Hugging Face API 使用指南。skills/1password/SKILL.md — 密钥安全获取方式。memory/patterns/playbooks.md — 浏览器自动化操作手册。scripts/external_ai_integration.py — 本技能的核心实现。playbooks/external-ai-integration-playbook.md — 外部 AI 编排操作手册。当某项任务可从外部 AI 推理中获益时,请查阅本技能以决定选用哪个模型及如何调用。将验证有效的模式存入 memory/patterns/tools.md。若外部 AI 反复失败且需人工干预配置,请更新 pending.md。
本技能通过将外部 AI 模型纳入助手工具集,显著提升了其自主性——无需启动子代理即可应对更广泛的任务类型,同时全程掌控工作流。
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习
最新文章