Add resource upload APIs
This commit is contained in:
86
README.md
86
README.md
@ -152,6 +152,8 @@ API=http://127.0.0.1:1934/memory-system
|
||||
| `POST` | `/sessions/{session_id}/extract` | 立即触发 OpenViking extract | 需要 |
|
||||
| `GET/POST` | `/sessions/{session_id}/context` | 查询 OpenViking 会话上下文,并用同一 query 搜索 EverOS 记忆 | 需要 |
|
||||
| `GET/POST` | `/openviking/tasks/{task_id}` | 查询 OpenViking 后台任务状态 | 需要 |
|
||||
| `POST` | `/resources` | 上传本地文件或远程 URL 到 OpenViking resources | 需要 |
|
||||
| `DELETE` | `/resources` | 删除 OpenViking resource URI | 需要 |
|
||||
| `POST` | `/search` | 同时搜索 OpenViking 和 EverOS 记忆 | 需要 |
|
||||
| `GET/POST` | `/users/{user_id}/profile` | 查询 EverOS profile,并补充 OpenViking 用户记忆搜索结果 | 需要 |
|
||||
|
||||
@ -355,6 +357,90 @@ curl -sS -X POST "$API/openviking/tasks/${TASK_ID}" \
|
||||
}'
|
||||
```
|
||||
|
||||
### `POST /resources`
|
||||
|
||||
上传文件资源到 OpenViking。网关只调用 OpenViking,不写 EverOS。
|
||||
|
||||
如果 `path` 是本地路径,文件必须能被 Memory System API 服务进程读取。网关会先调用 OpenViking `/api/v1/resources/temp_upload` 上传临时文件,取返回的 `temp_file_id`,再调用 `/api/v1/resources` 添加资源。
|
||||
|
||||
如果 `path` 是 `http://` 或 `https://` URL,网关会直接调用 OpenViking `/api/v1/resources`,并把 URL 作为 `path` 传给 OpenViking。
|
||||
|
||||
请求体:
|
||||
|
||||
| 参数 | 类型 | 必需 | 说明 |
|
||||
|---|---|---:|---|
|
||||
| `user_id` | string | 是 | 用户 ID |
|
||||
| `user_key` | string | 是 | `/users` 返回的 user key |
|
||||
| `path` | string | 是 | 本地文件路径,或 `http://` / `https://` URL |
|
||||
| `to` | string | 是 | 目标 OpenViking resource URI |
|
||||
| `reason` | string/null | 否 | 上传原因,透传给 OpenViking |
|
||||
| `wait` | bool | 否 | 是否等待处理完成,默认 `true` |
|
||||
| `directly_upload_media` | bool | 否 | 是否直接上传媒体,默认 `true` |
|
||||
|
||||
本地文件示例:
|
||||
|
||||
```bash
|
||||
curl -sS -X POST "$API/resources" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"user_id": "userA",
|
||||
"user_key": "'"$USER_KEY"'",
|
||||
"path": "/home/tom/memory-gateway/tests/大语言模型应用.pdf",
|
||||
"to": "viking://resources/userA/files/大语言模型应用.pdf",
|
||||
"reason": "userA 上传的文件",
|
||||
"wait": true,
|
||||
"directly_upload_media": true
|
||||
}'
|
||||
```
|
||||
|
||||
远程 URL 示例:
|
||||
|
||||
```bash
|
||||
curl -sS -X POST "$API/resources" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"user_id": "userA",
|
||||
"user_key": "'"$USER_KEY"'",
|
||||
"path": "https://example.com/images/photo.png",
|
||||
"to": "viking://resources/userA/images/photo.png",
|
||||
"reason": "userA 上传的远程图片",
|
||||
"wait": true,
|
||||
"directly_upload_media": true
|
||||
}'
|
||||
```
|
||||
|
||||
返回中的 `resource` 是 OpenViking `/api/v1/resources` 的原始响应,`backends.openviking` 保留调用状态和错误信息。
|
||||
|
||||
### `DELETE /resources`
|
||||
|
||||
删除 OpenViking resource URI。网关会调用 OpenViking:
|
||||
|
||||
```http
|
||||
DELETE /api/v1/fs?uri=<OPENVIKING_URI>&recursive=<true|false>
|
||||
X-API-Key: <user_key>
|
||||
```
|
||||
|
||||
Query 参数:
|
||||
|
||||
| 参数 | 类型 | 必需 | 说明 |
|
||||
|---|---|---:|---|
|
||||
| `user_id` | string | 是 | 用户 ID |
|
||||
| `user_key` | string | 是 | `/users` 返回的 user key |
|
||||
| `uri` | string | 是 | 要删除的 OpenViking URI |
|
||||
| `recursive` | bool | 否 | 是否递归删除,默认 `true` |
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
curl -sS -X DELETE -G "$API/resources" \
|
||||
--data-urlencode "user_id=userA" \
|
||||
--data-urlencode "user_key=$USER_KEY" \
|
||||
--data-urlencode "uri=viking://resources/userA/files/大语言模型应用.pdf" \
|
||||
--data-urlencode "recursive=true"
|
||||
```
|
||||
|
||||
返回中的 `resource` 是 OpenViking `/api/v1/fs` 删除接口的原始响应。
|
||||
|
||||
### `POST /search`
|
||||
|
||||
同时查询 OpenViking 和 EverOS,并合并结果。
|
||||
|
||||
Reference in New Issue
Block a user