FileChat Skill
Your personal RAG (Retrieval-Augmented Generation) document library backed by Google Drive.
Setup & Bootstrap
If the user asks to use FileChat or asks a question about their files, FIRST verify that the required environment variables are set in /workspace/skills/filechat/.env:
- 1.
GEMINI_API_KEY (For the embedding model text-embedding-004) - INLINECODE3 (The root Google Drive folder ID to index)
If they are missing, STOP and ask the user to provide them.
(To find the folder ID, they can look at the URL of the folder in Google Drive: https://drive.google.com/drive/folders/<FOLDER_ID>)
Create the .env file like this:
CODEBLOCK0
How to Sync the Library
When the user asks to "sync", "flush", or "update" their FileChat library, you must run the ingestion script. This connects to Google Drive, downloads all new/changed files (including PDFs, resolving shortcuts, and traversing sub-folders), chunks the text, gets embeddings, and saves them to a local ChromaDB.
CODEBLOCK1
(Warning: The first sync may take a few minutes depending on the folder size.)
How to Answer User Questions (RAG)
When a user asks a question about the contents of their documents (e.g., "What does my medical discharge say?"), you MUST query the local ChromaDB vector store to fetch the relevant text chunks.
CODEBLOCK2
The output will give you the most relevant text snippets, the original file names, and the Google Drive File IDs.
Use the text snippets to formulate a comprehensive answer for the user. Always cite the file name you are referencing.
How to Retrieve and Send a Physical File
If the user asks for the actual file (e.g., "Send me the discharge PDF"), first find the File ID using the query script (if you don't already know it).
Then, use the gws CLI to download the file into your workspace:
gws drive files get --params '{"fileId": "<FILE_ID>", "alt": "media"}' > /workspace/discharge.pdf
Then, reply to the user using the OpenClaw media attachment syntax:
MEDIA:/workspace/discharge.pdf to send the physical file directly to their chat window.
How to Store a New File for the User
If the user uploads a file and asks you to "store" or "save" it:
- 1. Upload it to their FileChat Google Drive folder using
gws:
gws drive files create \
--json '{"name": "filename.pdf", "parents": ["<FILECHAT_DRIVE_FOLDER_ID>"]}' \
--upload /path/to/uploaded/file.pdf
- 2. Trigger the sync process so the new file is immediately readable by the vector database:
CODEBLOCK5
FileChat 技能
您的个人 RAG(检索增强生成)文档库,由 Google Drive 提供支持。
设置与引导
如果用户要求使用 FileChat 或询问有关其文件的问题,请首先验证 /workspace/skills/filechat/.env 中是否设置了所需的环境变量:
- 1. GEMINIAPIKEY(用于嵌入模型 text-embedding-004)
- FILECHATDRIVEFOLDER_ID(要索引的根 Google Drive 文件夹 ID)
如果缺少这些变量,请停止并请用户提供它们。
(要查找文件夹 ID,用户可以查看 Google Drive 中该文件夹的 URL:https://drive.google.com/drive/folders/)
按如下方式创建 .env 文件:
bash
echo GEMINIAPIKEY=yourkeyhere > ./skills/filechat/.env
echo FILECHATDRIVEFOLDERID=yourfolderidhere >> ./skills/filechat/.env
如何同步库
当用户要求同步、刷新或更新其 FileChat 库时,您必须运行摄取脚本。该脚本会连接到 Google Drive,下载所有新增/更改的文件(包括 PDF、解析快捷方式以及遍历子文件夹),对文本进行分块,获取嵌入向量,并将其保存到本地 ChromaDB。
bash
cd ./skills/filechat && node sync.js
(注意:首次同步可能需要几分钟,具体取决于文件夹大小。)
如何回答用户问题(RAG)
当用户询问其文档内容的问题时(例如:我的医疗出院证明上写了什么?),您必须查询本地 ChromaDB 向量存储以获取相关的文本块。
bash
cd ./skills/filechat && node query.js 我的医疗出院证明上写了什么?
输出将为您提供最相关的文本片段、原始文件名以及 Google Drive 文件 ID。
使用这些文本片段为用户制定全面的答案。始终引用您所参考的文件名。
如何检索和发送实体文件
如果用户要求获取实际文件(例如:把出院证明 PDF 发给我),请首先使用查询脚本查找文件 ID(如果您还不知道的话)。
然后,使用 gws CLI 将文件下载到您的工作区:
bash
gws drive files get --params {fileId: , alt: media} > /workspace/discharge.pdf
然后,使用 OpenClaw 媒体附件语法回复用户:MEDIA:/workspace/discharge.pdf 将实体文件直接发送到他们的聊天窗口。
如何为用户存储新文件
如果用户上传文件并要求您存储或保存它:
- 1. 使用 gws 将其上传到他们的 FileChat Google Drive 文件夹:
bash
gws drive files create \
--json {name: filename.pdf, parents: [
DRIVEFOLDER_ID>]} \
--upload /path/to/uploaded/file.pdf
- 2. 触发同步过程,以便向量数据库能立即读取新文件:
bash
cd ./skills/filechat && node sync.js