https://github.com/smarthypercube/browse-api-serverless
一些为 AI 提供打开 URL 的能力的 API,均设计为部署在 AWS Lambda 上的无服务器云函数。
https://github.com/smarthypercube/browse-api-serverless
Last synced: 11 months ago
JSON representation
一些为 AI 提供打开 URL 的能力的 API,均设计为部署在 AWS Lambda 上的无服务器云函数。
- Host: GitHub
- URL: https://github.com/smarthypercube/browse-api-serverless
- Owner: SmartHypercube
- Created: 2023-12-17T17:31:06.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T02:27:25.000Z (about 2 years ago)
- Last Synced: 2024-05-15T20:15:14.719Z (about 2 years ago)
- Language: Python
- Size: 29.3 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# browse-api-serverless
一些为 AI 提供打开 URL 的能力的 API,均设计为部署在 AWS Lambda 上的无服务器云函数。
目前包含 4 个 API:
- `browse-text`:用 headless Chromium 尝试打开网页,提取网页标题和显示的所有文字。
- `github`:获取 GitHub 仓库的元信息和 README。
- `pdf`:下载 PDF 并提取其中的文字。
- `youtube`:获取 YouTube 视频标题、所属频道、描述、字幕。
## 部署
安装并配置以下依赖:
- [Serverless Framework](https://serverless.com/)
- [Node.js](https://nodejs.org/)
- [Python 3.9](https://www.python.org/)
- `zip`, `make` 等基础工具
然后在项目根目录下执行 `make`。运行结束后会输出各 API 的 URL。
## 使用
每个 API 都应当使用 `POST` 方法调用,请求体类似如下格式:
```json
{
"url": "https://example.com/"
}
```
每个 API 成功时都返回类似如下格式的 JSON。如果返回码不是 200,说明这个 API 无法打开指定的 URL。注意:某个 API 能打开某个 URL,并不意味着这个 API 是最佳选择。例如 `browse-text` API 可以打开 YouTube 视频的 URL,但是 `youtube` API 可能是更好的选择。
```json
{
"truncated": false,
"template": [
{"field": "foo", "name": "Foo", "type": "inline"},
{"field": "bar", "name": "Bar", "type": "inline"},
{"field": "baz", "name": "Baz", "type": "block"},
{"field": "qux", "name": "Qux", "type": "block"}
],
"data": {
"foo": "some text",
"baz": "some text\nmore text",
"qux": "some text\nmore text"
}
}
```
其中 `truncated` 指示是否截断了部分数据以满足 AWS Lambda 的 6MB 返回值大小限制,`template` 列出了 `data` 中所有可能的字段,以及如何格式化以便提供给 AI 模型的建议。
用户可以忽略 `template` 部分,直接以 JSON 格式传递 `data` 给 AI 模型,也可以按 `template` 给出的建议,用类似如下格式拼接字符串:
```plain
Foo: some text
Baz:
some text
more text
Qux:
some text
more text
```