返回顶部
e

external-ai-integration外部AI集成

Leverage external AI models (ChatGPT, Claude, Hugging Face, etc.) as tools via browser automation (Chrome Relay) and optional Hugging Face API. Use when you need to augment the assistant's capabilities with external LLMs for reasoning, summarization, code generation, or other tasks without spawning isolated sub‑agents.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
646
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

external-ai-integration

外部AI集成技能

本技能提供了将外部AI模型作为工具供助手按需调用的模式。它扩展了现有的浏览器自动化和API集成技能,使助手能够:

  • - 自动化交互:通过Chrome Relay(浏览器自动化)与ChatGPT、Claude、Gemini或其他基于网页的LLM进行交互。
  • 调用Hugging Face推理API:用于托管在Hugging Face Spaces上的模型(文本生成、摘要、翻译等)。
  • 将外部推理集成到助手自身工作流中——例如,向ChatGPT征求第二意见,使用Claude进行详细分析,或利用Hugging Face处理特定领域任务。
  • 避免生成孤立的子代理:通过将外部模型视为工具,将控制权和上下文保留在主助手会话中。

何时使用

  • - 你需要额外的推理能力、不同模型的视角,或主模型缺乏的专用模型(如代码生成、翻译)。
  • 任务受益于第二意见或并行评估(例如,审查代码、分析策略)。
  • 你想使用具有更大上下文窗口、更强编码能力或特定领域知识的模型(Claude、ChatGPT、Hugging Face模型)。
  • 你被要求“通过浏览器集成外部AI”或“将ChatGPT/Claude作为工具使用”。
  • 你需要调用Hugging Face推理API处理特定模型(如摘要、情感分析),并将结果整合到你的回复中。

核心模式

1. 基于网页的LLM浏览器自动化(Chrome Relay)

使用Chrome Relay自动化与ChatGPT、Claude、Gemini或任何其他需要浏览器界面的基于网页的LLM的交互。

前提条件:

  • - 已安装Chrome Relay扩展并附加了一个标签页(用户必须点击OpenClaw Browser Relay工具栏图标)。
  • 目标LLM网站(例如chatgpt.com、claude.ai)已登录(存在会话cookie)。
  • 基本熟悉浏览器自动化剧本(memory/patterns/playbooks.md – “浏览器自动化(Chrome Relay)”)。

步骤:

  1. 1. 附加到Chrome Relay配置文件(profile=chrome)。
  2. 导航到目标LLM(或重用已打开的标签页)。
  3. 拍摄快照以定位输入字段和发送按钮(使用refs=aria获取稳定引用)。
  4. 在输入字段中键入提示并提交(点击发送按钮或按回车键)。
  5. 等待响应(轮询新元素、检测输入指示器或使用固定超时)。
  6. 从适当的DOM元素中提取响应文本
  7. 将响应返回给助手的工作流

示例工作流:

python

这是一个概念性示例;实际实现使用浏览器工具调用。


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)和发送按钮
inputref = snap.findelement(role=textbox, name=Message)
sendref = snap.findelement(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)
responseelement = snap2.findlast_message()
return response_element.text

关键考虑因素:

  • - 会话持久性: 附加的标签页必须保持登录状态;避免导致注销的操作。
  • 速率限制: 注意LLM的速率限制和使用政策。
  • 错误处理: 检测验证码、“网络错误”消息或“重试”按钮,并优雅地回退。
  • 多轮对话: 通过保持同一标签页且不刷新来维护对话上下文。

2. Hugging Face推理API集成

对于托管在Hugging Face Spaces或推理API上的模型,你可以直接通过HTTP请求调用它们。

前提条件:

  • - Hugging Face API令牌(存储在1Password或环境变量中)。
  • 模型标识符(例如gpt2、google/flan-t5-large、microsoft/DialoGPT-medium)。
  • 了解模型的预期输入/输出格式。

步骤:

  1. 1. 检索API令牌(使用1Password技能或从~/.huggingface/token读取)。
  2. 构造请求(URL、标头、JSON负载)。
  3. 通过curl或使用requests Python模块的exec发送请求
  4. 解析响应并提取生成的文本。
  5. 处理错误(速率限制、模型加载、无效令牌)。

示例脚本(使用curl):

bash
#!/bin/bash
set -e

MODEL=google/flan-t5-large
PROMPT=Translate English to German: How are you?
APITOKEN=$(op read op://Personal/HuggingFace/apitoken)

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):

python
import requests
import os

def hf_inference(model, inputs, parameters=None):
apitoken = os.getenv(HFTOKEN) # 或通过1Password检索
url = fhttps://api-inference.huggingface.co/models/{model}
headers = {Authorization: fBearer {api_token}}
payload = {inputs: inputs}
if parameters:
payload.update(parameters)
resp = requests.post(url, headers=headers, json=payload)
resp.raiseforstatus()
return resp.json()

关键考虑因素:

  • - 成本: 推理API可能产生费用;监控使用情况。
  • 模型就绪状态: 某些模型需要加载;在参数中包含{options:{waitformodel:true}}。
  • 输出格式: 响应结构因模型而异;先通过测试调用进行检查。

3. 将外部AI编排为工具

助手在其自身的推理流程中调用外部AI,而不是生成子代理。

模式:

  1. 1. 确定需求: 决定使用哪个外部模型(ChatGPT用于创意任务,Claude用于分析,Hugging Face用于专用模型)。
  2. 准备提示: 格式化提示,包含清晰的指令、上下文和预期输出格式。
  3. 调用工具: 对基于网页的LLM使用浏览器自动化,对Hugging Face使用API调用。
  4. 集成结果: 解析、验证并将外部响应整合到你的答案中。
  5. 回退: 如果外部调用失败,继续使用你自己的推理或尝试替代方案。

示例决策逻辑:

python
def externalaiassist(task_type, prompt):
if tasktype == codereview:
# 通过浏览器自动化使用Claude
return ask_claude(prompt)
elif task_type == translation:
# 使用Hugging Face翻译模型
return hf_inference(Helsinki-NLP/opus-mt-en-de, prompt)
elif tasktype == creativewriting:
# 通过浏览器自动化使用ChatGPT
return ask_chatgpt(prompt)
else:
raise ValueError(fNo external AI configured for {task_type})

4. 外部模型的提示工程

外部模型可能需要与助手原生模型不同的提示风格。

  • - ChatGPT/Claude: 使用对话风格、系统提示和Markdown格式。
  • Hugging Face模型: 遵循模型预期的输入格式(例如,T5的Translate English to German: ...)。
  • 包含上下文: 在提示中提供必要的背景、约束和示例。
  • 指定输出格式: 要求JSON、要点、代码块等。

代码审查的示例提示:

You are an expert software engineer reviewing the following code snippet. Please:

  1. 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)

5. 错误处理和回退

外部服务可能失败;计划优雅降级。

  • - 浏览器自动化失败: 验证码、需要登录、网络错误。回退:尝试

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 external-ai-integration-1776420027 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 external-ai-integration-1776420027 技能

通过命令行安装

skillhub install external-ai-integration-1776420027

下载

⬇ 下载 external-ai-integration v1.0.0(免费)

文件大小: 10.99 KB | 发布时间: 2026-4-17 19:23

v1.0.0 最新 2026-4-17 19:23
Initial release: integrates external AI models as on-demand tools using browser automation and APIs.

- Automate ChatGPT, Claude, and other web-based LLMs via Chrome Relay browser automation, keeping context in the main session.
- Call Hugging Face Inference API directly for supported models (e.g., text generation, translation, summarization).
- Supports seamless incorporation of external AI outputs (second opinions, specialized tasks) without spawning sub-agents.
- Includes guidance for robust browser automation, API usage, credential handling, and error fallback.
- Designed to augment reasoning, code generation, and analysis with a variety of external models.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部