Files
nanocode/skills/context-hub/README.md
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

143 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Context Hub (chub) 技能
基于Andrew Ng团队的Context Hub项目,为nanobot提供API文档获取能力。
## 功能概述
- **搜索API文档**:查找第三方库、SDK和API的文档
- **获取文档内容**:获取特定语言的API参考文档
- **本地注解**:保存学习内容,跨会话持久化
- **文档反馈**:提供文档质量反馈
## 安装要求
chub CLI已预安装在系统中:
```bash
# 验证安装
which chub # 应该返回 /usr/bin/chub
```
## 文件结构
```
context-hub/
├── SKILL.md # 技能主文档
├── chub_wrapper.py # Python包装器
├── usage_example.py # 使用示例
└── README.md # 本文件
```
## 快速开始
### 方法1:直接使用chub CLI
```bash
# 搜索文档
chub search "openai" --json
# 获取文档
chub get openai/chat --lang py
# 添加注解
chub annotate openai/chat "重要提示:需要API密钥"
```
### 方法2:使用Python包装器
```python
from chub_wrapper import ChubWrapper
wrapper = ChubWrapper()
# 搜索
results = wrapper.search("fastapi")
# 获取文档
content = wrapper.get_doc("fastapi/package", language="py")
# 搜索并获取
result = wrapper.search_and_get("stripe", language="py")
```
## 在nanobot中使用
### 检测用户需求
当用户需要API文档时自动触发:
- "使用OpenAI API"
- "调用Stripe API"
- "需要FastAPI文档"
- "如何安装xxx包"
### 集成示例
```python
# 在nanobot技能中
from skills.context_hub.chub_wrapper import ChubWrapper
def handle_api_doc_request(user_query):
wrapper = ChubWrapper()
# 搜索相关文档
results = wrapper.search(user_query)
if not results:
return "未找到相关API文档"
# 获取第一个结果
first_result = results[0]
doc_id = first_result.get('id')
try:
# 获取文档
content = wrapper.get_doc(doc_id, language="py")
# 提取关键信息
key_info = extract_key_info(content)
return f"## {first_result.get('name')} 文档\n\n{key_info}"
except Exception as e:
return f"获取文档失败: {e}"
```
## 优势
1. **准确性**:减少AI幻觉,提供准确API信息
2. **时效性**:获取最新API版本文档
3. **效率**:增量获取,节省token
4. **学习能力**:通过注解持续改进
5. **多语言**:支持Python、JavaScript、TypeScript等
## 测试验证
所有核心功能均已测试验证:
- ✅ chub CLI功能正常
- ✅ 搜索和获取功能正常
- ✅ 注解功能正常
- ✅ Python包装器正常
- ✅ 集成示例运行成功
## 使用场景
1. **代码生成**:需要准确API信息时
2. **SDK集成**:需要特定语言SDK文档
3. **API调用**:需要最新API接口信息
4. **学习参考**:需要官方文档参考
## 注意事项
1. **内容覆盖**:可能缺少特定API文档
2. **社区维护**:文档质量依赖社区贡献
3. **网络依赖**:需要网络连接获取文档
4. **Node.js依赖**:chub需要Node.js环境
## 未来改进
1. 添加缓存机制
2. 支持更多编程语言
3. 集成到nanobot自动技能调用
4. 添加文档质量评估
5. 支持离线模式
## 相关链接
- [Context Hub GitHub](https://github.com/andrewyng/context-hub)
- [chub npm包](https://www.npmjs.com/package/@aisuite/chub)
- [原始技能文件](https://github.com/andrewyng/context-hub/blob/main/cli/skills/get-api-docs/SKILL.md)