Spaces:
Sleeping
Sleeping
Upload README.md
Browse files
README.md
CHANGED
@@ -1,207 +1,128 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
```
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
- `https-proxy-agent`: 支持 HTTPS 代理
|
129 |
-
|
130 |
-
## Cookie管理功能
|
131 |
-
|
132 |
-
本项目新增了Cookie管理功能,可以更方便地管理多个Notion Cookie,避免在.env文件中手动编辑长字符串。
|
133 |
-
|
134 |
-
### 使用方法
|
135 |
-
|
136 |
-
#### 1. 通过文件管理Cookie
|
137 |
-
|
138 |
-
在项目根目录创建一个`cookies.txt`文件,每行一个完整的Cookie字符串:
|
139 |
-
|
140 |
-
```
|
141 |
-
cookie1_string_here
|
142 |
-
cookie2_string_here
|
143 |
-
cookie3_string_here
|
144 |
-
```
|
145 |
-
|
146 |
-
然后在`.env`文件中设置:
|
147 |
-
|
148 |
-
```
|
149 |
-
COOKIE_FILE=cookies.txt
|
150 |
-
```
|
151 |
-
|
152 |
-
系统启动时会自动从该文件加载Cookie。
|
153 |
-
|
154 |
-
#### 2. 使用Cookie管理工具
|
155 |
-
|
156 |
-
项目提供了一个命令行工具来管理Cookie:
|
157 |
-
|
158 |
-
```bash
|
159 |
-
# 使用npm脚本运行
|
160 |
-
npm run cookie
|
161 |
-
|
162 |
-
# 或者全局安装后运行
|
163 |
-
npm link
|
164 |
-
notion-cookie
|
165 |
-
```
|
166 |
-
|
167 |
-
命令行工具支持以下功能:
|
168 |
-
|
169 |
-
- `help`: 显示帮助信息
|
170 |
-
- `list`: 列出所有已加载的Cookie
|
171 |
-
- `add`: 添加新的Cookie
|
172 |
-
- `validate`: 验证所有Cookie的有效性
|
173 |
-
- `remove`: 删除指定的Cookie
|
174 |
-
- `save`: 保存Cookie到文件
|
175 |
-
- `load`: 从文件加载Cookie
|
176 |
-
- `exit`: 退出程序
|
177 |
-
|
178 |
-
### Cookie轮询机制
|
179 |
-
|
180 |
-
系统会自动轮询使用所有有效的Cookie,当一个Cookie返回401错误(未授权)时,会自动将其标记为无效并切换到下一个Cookie。这样可以提高系统的可靠性和可用性。
|
181 |
-
|
182 |
-
### 文件格式支持
|
183 |
-
|
184 |
-
Cookie管理器支持两种文件格式:
|
185 |
-
|
186 |
-
1. 文本格式(.txt):每行一个Cookie
|
187 |
-
2. JSON格式(.json):包含Cookie数组的JSON文件
|
188 |
-
|
189 |
-
```json
|
190 |
-
{
|
191 |
-
"cookies": [
|
192 |
-
"cookie1_string_here",
|
193 |
-
"cookie2_string_here"
|
194 |
-
],
|
195 |
-
"updatedAt": "2023-08-01T12:00:00.000Z",
|
196 |
-
"count": 2
|
197 |
-
}
|
198 |
-
```
|
199 |
-
|
200 |
-
或者简单的数组:
|
201 |
-
|
202 |
-
```json
|
203 |
-
[
|
204 |
-
"cookie1_string_here",
|
205 |
-
"cookie2_string_here"
|
206 |
-
]
|
207 |
```
|
|
|
1 |
+
---
|
2 |
+
title: Notion
|
3 |
+
emoji: 📝
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: blue
|
6 |
+
sdk: docker
|
7 |
+
app_port: 7860
|
8 |
+
---
|
9 |
+
|
10 |
+
# Notion API 轻量级客户端 (Hugging Face Space)
|
11 |
+
|
12 |
+
这个项目提供了一个轻量级的 Notion API 客户端,可以作为 Web 服务部署在 Hugging Face Spaces 上。它兼容 OpenAI API 格式,让你可以将 Notion AI 作为后端集成到各种应用中。
|
13 |
+
|
14 |
+
## 🚀 在 Hugging Face Spaces 上部署
|
15 |
+
|
16 |
+
1. **创建 Space**: 在 Hugging Face 上创建一个新的 Space。
|
17 |
+
2. **选择 Docker SDK**: 在 "Choose an SDK" 步骤中,选择 "Docker"。
|
18 |
+
3. **上传文件**: 将此项目的所有文件(包括 `Dockerfile`)上传到你的 Space Git 仓库中。
|
19 |
+
4. **设置 Secrets**: 这是最重要的一步。你的 Notion 凭证和其他配置需要作为 Secrets 添加到 Space 中。进入你的 Space "Settings" 页面,找到 "Repository secrets" 部分,然后点击 "New secret" 添加以下变量:
|
20 |
+
|
21 |
+
* **必需**:
|
22 |
+
* `NOTION_COOKIE`: 你的 Notion Cookie。你可以通过浏览器开发者工具获取。
|
23 |
+
* **可选**:
|
24 |
+
* `NOTION_SPACE_ID`: 你的 Notion Space ID。
|
25 |
+
* `NOTION_ACTIVE_USER_HEADER`: 你的 Notion 用户 ID。
|
26 |
+
* `PROXY_URL`: 如果你需要通过代理访问 Notion,请设置此项 (例如 `http://user:pass@host:port`)。
|
27 |
+
* `PROXY_AUTH_TOKEN`: 如果你的代理需要单独的认证令牌,请设置此项。
|
28 |
+
* `COOKIE_FILE`: 如果你使用文件管理多个 Cookie,请设置为文件名 (例如 `cookies.txt`)。请确保该文件也已上传到仓库中。
|
29 |
+
|
30 |
+
**注意**: `PORT` 环境变量由 Hugging Face 自动处理,你无需设置。
|
31 |
+
|
32 |
+
5. **等待部署**: 添加完 Secrets 后,Hugging Face 会自动构建 Docker 镜像并部署你的应用。你可以在 "Logs" 标签页查看部署进度和应用日志。部署成功后,你的 API 端点即可使用。
|
33 |
+
|
34 |
+
## 📖 API 使用说明
|
35 |
+
|
36 |
+
服务启动后,你可以通过你的 Space URL 访问 API。
|
37 |
+
|
38 |
+
**基础 URL**: `https://<your-space-name>.hf.space`
|
39 |
+
|
40 |
+
### API 端点
|
41 |
+
|
42 |
+
- `GET /v1/models` - 获取可用模型列表 (主要是为了兼容 OpenAI 客户端)
|
43 |
+
- `POST /v1/chat/completions` - 核心的聊天完成端点
|
44 |
+
- `GET /health` - 健康检查端点
|
45 |
+
|
46 |
+
### 示例: 使用 cURL 调用
|
47 |
+
|
48 |
+
```bash
|
49 |
+
curl -X POST https://<your-space-name>.hf.space/v1/chat/completions \
|
50 |
+
-H "Content-Type: application/json" \
|
51 |
+
-d '{
|
52 |
+
"model": "openai-gpt-4.1",
|
53 |
+
"messages": [
|
54 |
+
{"role": "user", "content": "你好,请介绍一下你自己"}
|
55 |
+
],
|
56 |
+
"stream": true
|
57 |
+
}'
|
58 |
+
```
|
59 |
+
*请将 `<your-space-name>` 替换为你的 Space 名称。*
|
60 |
+
|
61 |
+
## 🍪 Cookie 管理
|
62 |
+
|
63 |
+
为了提高服务的稳定性,你可以提供多个 Notion Cookie。
|
64 |
+
|
65 |
+
### 通过文件管理 Cookie
|
66 |
+
|
67 |
+
1. 在项目根目录创建一个 `cookies.txt` 或 `cookies.json` 文件。
|
68 |
+
2. 将文件上传到你的 Space 仓库。
|
69 |
+
3. 在 Space Secrets 中设置 `COOKIE_FILE` 为你的文件名 (例如 `cookies.txt`)。
|
70 |
+
|
71 |
+
系统启动时会自动从该文件加载Cookie。
|
72 |
+
|
73 |
+
**`cookies.txt` 示例:** (每行一个Cookie)
|
74 |
+
```
|
75 |
+
cookie1_string_here
|
76 |
+
cookie2_string_here
|
77 |
+
```
|
78 |
+
|
79 |
+
**`cookies.json` 示例:**
|
80 |
+
```json
|
81 |
+
{
|
82 |
+
"cookies": [
|
83 |
+
"cookie1_string_here",
|
84 |
+
"cookie2_string_here"
|
85 |
+
]
|
86 |
+
}
|
87 |
+
```
|
88 |
+
|
89 |
+
### Cookie 轮询机制
|
90 |
+
|
91 |
+
系统会自动轮询使用所有有效的Cookie。当一个Cookie失效时(例如返回401错误),会自动切换到下一个有效的Cookie,确保服务不中断。
|
92 |
+
|
93 |
+
---
|
94 |
+
|
95 |
+
## 本地开发参考
|
96 |
+
|
97 |
+
以下信息用于在本地计算机上运行和开发。
|
98 |
+
|
99 |
+
### 依赖项
|
100 |
+
```bash
|
101 |
+
npm install
|
102 |
+
```
|
103 |
+
|
104 |
+
### 环境变量
|
105 |
+
创建 `.env` 文件,设置以下环境变量:
|
106 |
+
```
|
107 |
+
NOTION_COOKIE=your_notion_cookie_here
|
108 |
+
NOTION_SPACE_ID=optional_space_id
|
109 |
+
NOTION_ACTIVE_USER_HEADER=optional_user_id
|
110 |
+
PROXY_URL=optional_proxy_url
|
111 |
+
PROXY_AUTH_TOKEN=your_auth_token
|
112 |
+
PORT=7860
|
113 |
+
```
|
114 |
+
|
115 |
+
### 启动服务
|
116 |
+
```bash
|
117 |
+
npm start
|
118 |
+
```
|
119 |
+
|
120 |
+
### Cookie 管理命令行工具
|
121 |
+
项目提供了一个命令行工具来方便地管理 `cookies.json` 文件。
|
122 |
+
```bash
|
123 |
+
# 运行命令行工具
|
124 |
+
npm run cookie
|
125 |
+
|
126 |
+
# 支持的命令
|
127 |
+
help, list, add, validate, remove, save, load, exit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
```
|