关于 rw-integrate-documents
面向使用 Runway Avatar 的开发者,提供将文本文档创建并关联到 Avatar 的集成流程,让 Avatar 在对话中引用领域知识。支持从本地文件读取内容及以程序方式更新文档。
主要功能
- 01创建文本或 Markdown 文档
- 02将文档关联到 Avatar
- 03支持单个或多个文档
- 04从本地文件加载内容
- 05以程序方式更新知识内容
适用场景
- 01为客服 Avatar 添加常见问题与政策
- 02为教育或测验 Avatar 提供材料
- 03同步 CMS 或数据库中的知识
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ runwayml/ skills --skill rw-integrate-documents安装后在 Claude Code 中输入/rw-integrate-documents确认已加载。
详细介绍
集成文档(知识库)
**前置条件:**先运行
+rw-check-compatibility。集成前运行+rw-fetch-api-reference,以加载最新的 API 参考。+rw-setup-api-key— 必须配置 API 凭据使用方:
+rw-integrate-characters— 文档会关联到 Avatar,为其提供特定领域的知识
让你的 Characters 获取特定领域的知识。上传内容,供 Avatar 在对话中参考,从而给出准确且符合上下文的回复。
何时使用文档
| 使用场景 | 示例内容 |
|---|---|
| 客户支持 | 常见问题、产品信息、公司政策、退货流程 |
| 测验和游戏 | 题库、正确答案、计分规则 |
| 教育 | 课程材料、参考内容、学习目标 |
| 品牌体验 | 品牌指南、宣传信息、产品目录 |
限制
- 每个 Avatar 最多支持 50,000 个令牌的知识
- 支持的格式:纯文本和 Markdown
- 计划在未来版本中支持更多格式
流程
流程为:创建文档 → 将其关联到 Avatar
步骤 1:创建文档
Node.js
import RunwayML from '@runwayml/sdk';
const client = new RunwayML();
const document = await client.documents.create({
name: 'Product FAQ',
content: `# Product FAQ
## What is your return policy?
We offer a 30-day return policy for all unused items in original packaging.
## How do I track my order?
Log in to your account and visit the Orders page. You'll find tracking information for all shipped orders.
## Do you offer international shipping?
Yes, we ship to over 50 countries. Shipping costs and delivery times vary by destination.`,
});
console.log('Document created:', document.id);
Python
from runwayml import RunwayML
client = RunwayML()
document = client.documents.create(
name='Product FAQ',
content="""# Product FAQ
## What is your return policy?
We offer a 30-day return policy for all unused items in original packaging.
## How do I track my order?
Log in to your account and visit the Orders page.
## Do you offer international shipping?
Yes, we ship to over 50 countries.""",
)
print('Document created:', document.id)
步骤 2:将文档关联到 Avatar
更新 Avatar 并附加文档。这会替换所有现有的文档附件——请传入所有要关联的文档 ID。
Node.js
await client.avatars.update(avatarId, {
documentIds: [document.id],
});
Python
client.avatars.update(
avatar_id,
document_ids=[document.id],
)
多个文档
你可以将多个文档关联到同一个 avatar(总量必须低于 50,000 个令牌):
const faq = await client.documents.create({
name: 'FAQ',
content: '...',
});
const policies = await client.documents.create({
name: 'Company Policies',
content: '...',
});
await client.avatars.update(avatarId, {
documentIds: [faq.id, policies.id],
});
步骤 3:启动会话
关联文档后,Avatar 会在对话期间自动访问其中的知识。像往常一样启动会话即可——无需额外配置:
const session = await client.realtimeSessions.create({
model: 'gwm1_avatars',
avatar: {
type: 'custom',
avatarId: avatarId,
},
});
session = client.realtime_sessions.create(
model='gwm1_avatars',
avatar={
'type': 'custom',
'avatar_id': avatar_id,
},
)
有关完整的会话创建、轮询和 WebRTC 流程,请参阅 +rw-integrate-characters。
集成模式
从文件加载文档
从本地文件读取内容并创建文档:
import fs from 'fs';
import RunwayML from '@runwayml/sdk';
const client = new RunwayML();
// Read a local markdown file
const content = fs.readFileSync('./knowledge/product-faq.md', 'utf-8');
const document = await client.documents.create({
name: 'Product FAQ',
content,
});
from pathlib import Path
from runwayml import RunwayML
client = RunwayML()
content = Path('./knowledge/product-faq.md').read_text()
document = client.documents.create(
name='Product FAQ',
content=content,
)
动态更新知识
以编程方式更新文档——适用于与 CMS 或数据库同步:
// Example: API endpoint to update character knowledge
app.post('/api/avatar/update-knowledge', async (req, res) => {
const { avatarId, documents } = req.body;
// Create new documents
const docIds = [];
for (const doc of documents) {
const created = await client.documents.create({
name: doc.name,
content: doc.content,
});
docIds.push(created.id);
}
// Link all documents to the avatar (replaces existing)
await client.avatars.update(avatarId, {
documentIds: docIds,
});
res.json({ success: true, documentCount: docIds.length });
});
提示
- 使用 Markdown组织内容——标题有助于 Avatar 浏览知识。
- 保持简洁——尽量远低于 50,000 个令牌的上限,以获得最佳检索质量。
- 按主题组织——使用多份主题明确的文档,效果优于一份庞大的文档。
- 定期更新——内容发生变化时,重新创建文档以保持知识库最新。
- 也可以通过 Developer Portal UI 管理文档。
评论
支持 Markdown