subaitang commited on
Commit
2e99723
·
verified ·
1 Parent(s): 8b6a43f

Upload 48 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ wiki/img/files.png filter=lfs diff=lfs merge=lfs -text
37
+ wiki/img/settings.png filter=lfs diff=lfs merge=lfs -text
38
+ wiki/img/spaces.png filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # 安装 unzip 工具
6
+ RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
7
+
8
+ COPY app.zip .
9
+ COPY requirements.txt .
10
+ COPY version.txt .
11
+ RUN mkdir -p app
12
+ # 解压 app.zip 文件
13
+ RUN unzip app.zip -d app && rm app.zip
14
+
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
+
17
+ # 环境变量 (在 Hugging Face Spaces 中设置)
18
+ # ENV GEMINI_API_KEYS=your_key_1,your_key_2,your_key_3
19
+
20
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
Dockerfile_git ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY ./app /app/app
6
+ COPY requirements.txt .
7
+ COPY version.txt .
8
+
9
+ RUN pip install --no-cache-dir -r requirements.txt
10
+
11
+ # 环境变量 (在 Hugging Face Spaces 中设置)
12
+ # ENV GEMINI_API_KEYS=your_key_1,your_key_2,your_key_3
13
+
14
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app.zip/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
3
+ size 0
app.zip/api/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b33076f81c7ba65917b8bcb637aeb49e7c4396a9e3a2c93c8e6bb264f5d0c2a5
3
+ size 216
app.zip/api/auth.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c80d3c9e92dca7e539a74bd02d64c5b0d7f101885d35ef62c857f25aafd9e897
3
+ size 638
app.zip/api/client_disconnect.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ea1a1bc928ae71b90959cdcd299d9dddd90a0cfb2b9d514ab1ccce65272ab0c
3
+ size 6246
app.zip/api/dashboard.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edbdbec553bf03dfb3996054bc0b9d2bfbe72c59dab48ff86bdf01803c6159b8
3
+ size 3799
app.zip/api/gemini_handlers.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95059dc4ad20d53f2bcd52074c65c3e2a0531a2eaa477ea5bb1150a9932e1ab7
3
+ size 2648
app.zip/api/logging_utils.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f8c81d17eb303c0a5908660a1db7ceac475b1bf7bbc0c6cb7c2c8178e45654bf
3
+ size 327
app.zip/api/nonstream_handlers.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef4f3bd99fe16b55a7a6dcaa34c97c1db265dd256b838b94af3c0633b8606b6e
3
+ size 6294
app.zip/api/request_handlers.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f0bb4c9e7f86d827b89983f922d3a36e4a954edb05a2a872237fe11184032e4f
3
+ size 7528
app.zip/api/routes.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d937bfdd702c698058973c294eeb5f5e4a2945d5c5fb26c82911a0f84f78acab
3
+ size 8829
app.zip/api/stream_handlers.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21e2e9372fd09acd227a929d9abe0be56d47652ddc862b06a6970b8582495e16
3
+ size 15630
app.zip/config/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64bcf6a3723417693a5daa142b552b1f7179d1e8c8f173d9974d6c125deb6b5e
3
+ size 95
app.zip/config/safety.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1ce851b3017f4889d323bc2989e21647fbb5259e7c5948a71ed4e1c4aea44e4d
3
+ size 1074
app.zip/config/settings.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:416c04b4afa5234dbc76f0b076c3e6031935478908ffbcecf457044c884c6018
3
+ size 2888
app.zip/main.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cb4cea15f6015db27d00ff8fe1110113ede6b880019f8cda429b100301780f47
3
+ size 10696
app.zip/models/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d0876542057cc40c776c4285093b238aa94867e6d884a4d79d6d0c154a9e059f
3
+ size 311
app.zip/models/schemas.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1e4065509a0b09fcb55ca2d3464ee3bcf6a5e5302200185f646d9a724232c64
3
+ size 1153
app.zip/services/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58762456d11c2b853bc04d8029540e6a98daff4aa25a80058739008bd2cfe912
3
+ size 154
app.zip/services/gemini.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8cad6c592d53cfe17db6f0ab05871f8b1b98e258f472e14c3fca42ec6c8db11
3
+ size 16895
app.zip/templates/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92e31f8258e7512ef6242febf5849061d923528b9a14dbbdee44a020bc50168c
3
+ size 34
app.zip/templates/index.html ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a334dc181a0e901ec738800968b63b4349bdf0aa2285e56c531458ad2e66c1a4
3
+ size 21321
app.zip/utils/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b1520ee093ba09374a8efb3e4632da7072929c06376c7899a59e62887ce419a
3
+ size 772
app.zip/utils/api_key.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9b8f6d00c69a5d6fcec5de3d2af5338923652751b9348fdf489ebae2870d0a5
3
+ size 3411
app.zip/utils/cache.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6da33838bf49fc87aaf3eb2947a12795757e2481e57b6e6d0ee382fa9b318604
3
+ size 5384
app.zip/utils/error_handling.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72d28758cfeab1afbce83893163ba853caf3669b44e30d0f3e2ebc1640181867
3
+ size 7553
app.zip/utils/logging.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b17dedef55b59beffa04e0620572d2f97f1e5a92aa2971a8f54895b38e04560c
3
+ size 2540
app.zip/utils/maintenance.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:acd32574a13f7c83217ad15261eb53cbf24684a3c793152cef17ae9119d72f6f
3
+ size 3254
app.zip/utils/rate_limiting.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0882dbf2e3c2db53fe1741189b72bec1b5d1b978d0a77a24533c01f86aac9fdf
3
+ size 1391
app.zip/utils/request.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1911cbb382f39ac543a4d1d9d67e4725a9496a8c33d94c0796bae4debd92a36f
3
+ size 2883
app.zip/utils/response.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:670512145b9b88e4351336f2ef7bd3a451108d740b2d9216079c27dc365754b6
3
+ size 1842
app.zip/utils/stats.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8d67b0e9d5a74dcbe556440761d62aca132f8c042ac313b4446aba89d0ae190
3
+ size 7456
app.zip/utils/version.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58eb42861fc192be4c8c9b9df20ec42a65234e99a076bac8b248eda97e5b57ee
3
+ size 2196
readme.md ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 Gemini API Proxy
2
+
3
+ 基于某论坛上一位大佬[@Mrjwj34](https://github.com/Moonfanz)基于另一位大佬[@Moonfanzp](https://github.com/Moonfanz)的代码的修改修改而来,由于大佬好长时间没有维护,我自己也遇到些bug,就魔改了一下,求star求star求star
4
+
5
+ 这是一个基于 FastAPI 构建的 Gemini API 代理,旨在提供一个简单、安全且可配置的方式来访问 Google 的 Gemini 模型。适用于在 Hugging Face Spaces 上部署,并支持openai api格式的工具集成。
6
+ ### 使用文档
7
+ - [使用文档](./wiki/wiki.md)
8
+ ### 更新日志
9
+ * v0.0.5beta
10
+ * 新增“**伪装信息**功能,默认开启,可在转发消息中添加随机字符串伪装消息,防止被检测
11
+ * 修复若干bug
12
+ * 为前端界面新增**功能配置**栏目,可检查功能是否开启
13
+ * 北京时间16点自动重置统计数据
14
+ * 在环境变量中新增`RANDOM_STRING`,是否启用伪装信息,默认值为true
15
+ * 在环境变量中新增`RANDOM_STRING_LENGTH`,伪装信息长度,默认为20
16
+ * 为git用户提供单独的`Dockerfile_git`
17
+ * v0.0.4
18
+ * 修改版本更新逻辑,现在为每四小时检查一次版本更新
19
+ * 前端界面所有数据数据实现动态更新
20
+ * 新增**单api使用次数统计**,在原API调用统计下方新增可折叠的单api使用次数统计,同时提供进度条查看剩余使用次数
21
+ * 在环境变量中新增`API_KEY_DAILY_LIMIT`,为单api 24小时最大使用次数,默认值为25
22
+ * 在环境变量中新增`BLOCKED_MODELS`,为需要屏蔽的模型名称,多个模型用英文逗号分隔
23
+
24
+ * v0.0.3beta
25
+ * 完善了客户端断开连接的处理逻辑(感谢[@warming-afternoon](https://github.com/warming-afternoon))
26
+ * 新增“假流式传输模式”,该模式默认开启,以解决在某些情况下客户端断开连接的问题。如需关闭,请将环境变量 `FAKE_STREAMING` 设置为 `false`。
27
+
28
+ * v0.0.2 修复了在log中错误暴露apikey的问题,修改了客户端断开连接的处理逻辑(感谢[@warming-afternoon](https://github.com/warming-afternoon))
29
+
30
+ ## ✨ 主要功能:
31
+
32
+ ### 🔑 API 密钥轮询和管理
33
+
34
+ ### 📑 模型列表接口
35
+
36
+ ### 💬 聊天补全接口:
37
+
38
+ * 提供 `/v1/chat/completions` 接口,支持流式(streaming)和非流式响应,与 OpenAI API 格式兼容。
39
+ * 自动将 OpenAI 格式的请求转换为 Gemini 格式。
40
+
41
+ ### 🔒 密码保护(可选):
42
+
43
+ * 通过 `PASSWORD` 环境变量设置密码。
44
+ * 提供默认密码 `"123"`。
45
+
46
+ ### 🚦 速率限制和防滥用:
47
+
48
+ * 通过环境变量自定义限制:
49
+ * `MAX_REQUESTS_PER_MINUTE`:每分钟最大请求数(默认 30)。
50
+ * `MAX_REQUESTS_PER_DAY_PER_IP`:每天每个 IP 最大请求数(默认 600)。
51
+ * 超过速率限制时返回 429 错误。
52
+
53
+ ### 🧩 服务兼容
54
+
55
+ * 提供的接口与 OpenAI API 格式兼容,便于接入各种服务
56
+
57
+ ## ⚠️ 注意事项:
58
+
59
+ * **强烈建议在生产环境中设置 `PASSWORD` 环境变量,并使用强密码。**
60
+ * 根据你的使用情况调整速率限制相关的环境变量。
61
+ * 确保你的 Gemini API 密钥具有足够的配额。
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ httpx
4
+ python-dotenv
5
+ requests
6
+ apscheduler
7
+ jinja2
version.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ version=0.0.5
wiki/Termux.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Termux 安装与配置 Hajimi 项目教程 由[@天命不又](https://github.com/tmby)编写
2
+
3
+ ## 一、切换 Termux 清华源(有“魔法”的可跳过)
4
+
5
+ ```bash
6
+ sed -i 's@^\(deb.*stable main\)$@#\1\ndeb https://mirrors.tuna.tsinghua.edu.cn/termux/apt/termux-main stable main@' $PREFIX/etc/apt/sources.list
7
+ ```
8
+
9
+ ## 二、安装必要依赖
10
+
11
+ ```bash
12
+ apt update && apt --yes upgrade && apt --yes install git python rust
13
+ ```
14
+
15
+ ## 三、配置 pip 使用清华源(有“魔法”的可跳过)
16
+
17
+ ```bash
18
+ pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
19
+ ```
20
+
21
+ ## 四、配置 Rust 使用清华源(有“魔法”的可跳过)
22
+
23
+ ```bash
24
+ export CARGO_REGISTRIES_CRATES_IO_INDEX="https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
25
+ ```
26
+
27
+ ## 五、克隆项目源码(有“魔法”的可去除加速链接)
28
+
29
+ ```bash
30
+ git clone https://github.boki.moe/https://github.com/wyeeeee/hajimi
31
+ ```
32
+
33
+ ## 六、进入项目目录
34
+
35
+ ```bash
36
+ cd hajimi
37
+ ```
38
+
39
+ ## 七、安装 Python 依赖
40
+
41
+ ```bash
42
+ pip install tzdata -r requirements.txt
43
+ ```
44
+
45
+ > **提示**:安装和构建过程会比较慢,请耐心等待。
46
+
47
+ ---
48
+
49
+ ## 八、配置 Termux Widget 启动脚本
50
+
51
+ ### 1. 安装 Termux Widget 插件
52
+ 项目地址:[termux-widget](https://github.com/termux/termux-widget)
53
+
54
+ ### 2. 使用 MT 管理器:
55
+ - 打开 Termux 的根目录
56
+ - 新建 `.shortcuts` 文件夹
57
+ - 在其中创建一个空白脚本文件(例如 `哈基米启动`),内容如下:
58
+
59
+ ```bash
60
+ #!/data/data/com.termux/files/usr/bin/bash
61
+
62
+ HAJIMI_PATH=/data/data/com.termux/files/home/hajimi
63
+ export GEMINI_API_KEYS="key1,key2,key3"
64
+
65
+ termux-wake-lock
66
+ cd $HAJIMI_PATH
67
+ uvicorn app.main:app --reload --host 127.0.0.1 --port 7860
68
+ ```
69
+
70
+ ### 3. 添加桌面小部件
71
+ - 在桌面添加 Termux Widget 快捷方式
72
+ - 点击刚才创建的脚本,即可一键启动 Hajimi 服务
73
+
74
+ ---
75
+
76
+ ## 九、访问前端页面
77
+
78
+ 启动服务后,在浏览器中访问以下地址查看前端界面:
79
+
80
+ ```
81
+ http://127.0.0.1:7860
82
+ ```
83
+
84
+ > **注意**:此地址只能在当前设备本地访问,如需远程访问请进行端口转发或内网穿透设置。
wiki/docker.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用 Docker 部署 Gemini 轮询魔改版教程 由 **北极星星** 编写
2
+
3
+ ## 一、准备工作
4
+
5
+ ### 1.1 下载项目
6
+
7
+ 从 releases 下载最新版本,并解压到任意目录。
8
+
9
+ ### 1.2 配置环境变量
10
+
11
+ 在项目根目录下创建 `.env` 文件,配置必要环境变量,示例如下:
12
+
13
+ ```
14
+ GEMINI_API_KEYS=key1,key2,key3
15
+ PASSWORD=your_password
16
+ TZ=Asia/Shanghai
17
+ ```
18
+
19
+ 按需修改上述值,注意⚠️key必须使用英文逗号间隔。
20
+
21
+ ## 二、构建并运行 Docker 容器
22
+
23
+ ### 2.1 构建镜像
24
+
25
+ 在项目根目录打开终端,执行命令构建 Docker 镜像:
26
+
27
+ ```bash
28
+ cd 项目文件夹完整路径(例如:cd /volume3/docker/hagemi)
29
+ docker build -t hajimi-app .
30
+ ```
31
+
32
+ 此过程可能需一些时间,取决于网络和系统性能。
33
+
34
+ ### 2.2 运行容器
35
+
36
+ 镜像构建完成后,执行命令启动 Docker 容器,如端口被占用需修改左侧端口号:
37
+
38
+ ```bash
39
+ docker run -d -p 7860:7860 --env-file .env hajimi-app
40
+ ```
41
+
42
+ ## 三、验证部署
43
+
44
+ ### 3.1 检查容器状态
45
+
46
+ 打开 docker 查看 hajimi-app 容器运行状态,确认正常启动。
47
+
48
+ ### 3.2 访问应用
49
+
50
+ 打开浏览器,访问 http://localhost:7860,若看到应用界面,则部署成功。
51
+
52
+ API 地址:http://localhost:7860/v1
53
+ key:PASSWORD=your_password
54
+
55
+ ## 四、容器更新
56
+
57
+ ### 4.1 更新脚本
58
+
59
+ 将下面 gemini_docker_update.sh 脚本按需修改保存为一个 .sh 文件:
60
+
61
+ ```bash
62
+ # 停止容器
63
+ docker stop hajimi-app
64
+ # 删除容器
65
+ docker rm hajimi-app
66
+ # 进入项目所在目录
67
+ cd /volume3/docker/hagemi
68
+ # 使用以下命令拉取最新代码
69
+ git pull origin main
70
+ # 构建新的 Docker 镜像
71
+ docker build -t hajimi-app .
72
+ # 运行新容器
73
+ docker run -d -p 7860:7860 --env-file .env hajimi-app
74
+ # 查看容器状态
75
+ docker ps -a | grep hajimi-app
76
+ ```
77
+
78
+ ### 4.2 脚本存放位置
79
+
80
+ 把 gemini_docker_update.sh 脚本存放在项目根目录,例如项目文件路径是 /volume3/docker/hagemi,便将脚本存放在 /volume3/docker/hagemi。
81
+
82
+ ### 4.3 执行更新
83
+
84
+ 进入终端输入命令,执行更新脚本:
85
+
86
+ ```bash
87
+ cd /volume3/docker/hagemi
88
+ ./gemini_docker_update.sh
89
+ ```
90
+
91
+ 通过以上步骤,即可使用 Docker 成功部署 Gemini 轮询魔改版应用。
wiki/img/KEYS.png ADDED
wiki/img/app.png ADDED
wiki/img/create_space.png ADDED
wiki/img/files.png ADDED

Git LFS Details

  • SHA256: a12e1d4566bd49280107c5d46887ab69fb32231dee52d18ec3f533c4ee347bb5
  • Pointer size: 131 Bytes
  • Size of remote file: 106 kB
wiki/img/secrets.png ADDED
wiki/img/settings.png ADDED

Git LFS Details

  • SHA256: 1c8f10d54ccc1f14a495da694f73e03aef1e67fcdd8281140794c1bcfefbc36d
  • Pointer size: 131 Bytes
  • Size of remote file: 190 kB
wiki/img/spaces.png ADDED

Git LFS Details

  • SHA256: 6caac27f11ef1d50357a1957a2215cf71022afdfdbd012e1b8cdbac338e1febe
  • Pointer size: 131 Bytes
  • Size of remote file: 546 kB
wiki/img/upload_files.png ADDED
wiki/wiki.md ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # hajimi使用教程
2
+
3
+ ## 1. 安装
4
+ ### 1.1 下载
5
+ - 从[releases](https://github.com/wyeeeee/hajimi/releases))下载最新版本。
6
+ - 下载完成后解压到任意目录。
7
+
8
+ ### 1.2 使用huggingface space部署项目
9
+ - 在[huggingface](https://huggingface.co)注册账号。
10
+ - 注册完成后,进入[spaces](https://huggingface.co/spaces)如图所示,点击new spaces。<br>![spaces](./img/spaces.png)
11
+ - 如图所示,填入创建选项,注意space name不要使用符号,填写完成后,点击create space<br>![create_space](./img/create_space.png)
12
+ - 如图所示,选择upload files<br>![files](./img/files.png)
13
+ - 如图所示,将1.1下载并解压的文件全部拖入,上传完成后点击Commit changes to main<br>![upload_files](./img/upload_files.png)
14
+
15
+ ### 1.2 配置环境变量
16
+ - 如图所示,进入settings界面<br>![settings](./img/settings.png)
17
+ - 如图所示,在settings界面中找到Variables and secrets,点击new secrets<br>![secrets](./img/secrets.png)
18
+ - 添加环境变量,如图所示为添加GEMINI_API_KEYS环境变量,在value中填入具体apikey<br>![KEYS](./img/KEYS.png)
19
+ - 等待项目部署完成,app界面显示如图界面,即完成<br>![app](./img/app.png)
20
+
21
+ ### 1.3 环境变量说明
22
+ #### 重要环境变量
23
+ - `GEMINI_API_KEYS`:从google ai studio 获取的API密钥,支持多个API密钥,以英文逗号分隔(例:apikey1,apikey2,apikey3)。
24
+ - `PASSWORD`:用户访问所需的password,如不填写默认为123。
25
+ #### 可选环境变量
26
+ - `MAX_REQUESTS_PER_MINUTE`:(可选)每分钟最大请求数。
27
+ - `MAX_REQUESTS_PER_DAY_PER_IP`:(可选)每天每个 IP 最大请求数。
28
+ - `FAKE_STREAMING`:(可选)是否启用假流式传输,默认为true。
29
+ - `API_KEY_DAILY_LIMIT`: 单api 24小时最大使用次数,默认值为25
30
+ - `BLOCKED_MODELS`,(可选)需要屏蔽的模型名称,多个模型用英文逗号分隔
31
+ - `RANDOM_STRING`,是否启用伪装信息,默认值为true
32
+ - `RANDOM_STRING_LENGTH`,伪装信息长度,默认为20
33
+ ### 1.4 在酒馆中使用
34
+ 在酒馆api连接配置中,选择兼容openai格式,URL格式为`https://(huggingface用户名)-(huggingface项目名).hf.space/v1`(注意为https)。自定义 API 密钥为1.3中配置的`PASSWORD`。
35
+
36
+ ### 1.5 假流式传输模式说明
37
+ - 如需使用假流式传输模式,请确保酒馆中的预设配置里的流式传输选项为打开。
38
+ - 众所周知,gemini无法使用流式传输模式输出,但酒馆在非串流模式下等待一段时间后会自动中断连接,导致请求终止,同时酒馆不支持自定义最长等待时间,因此本项目提出假串流模式,在使用非串流模式获取gemini回复的等待期间,持续向酒馆发送空包保持连接,经测试能有效避免酒馆在gemini非串流模式下的自动中断连接情况。
39
+ - 目前项目在0.0.3测试版中已默认开启假流式传输模式,如需关闭,请将环境变量`FAKE_STREAMING`设置为false。
40
+
41
+ ### 1.6 问题解决
42
+ - `429报错,空回复`:内容触发了谷歌的审查机制,暂时的解决方案是在破限的最前方手动新增一栏,里面随便填点东西就不429了(或者把破线的开头那段丢给ai重新生成,意思相同,文字跟原来不同) ,或寻求破限作者/社区的帮助。
43
+ - `408报错,酒馆断开连接`:参考1.5中假流式传输模式说明,开启假流式传输模式。
44
+
45
+ ### 1.7 💻 本地运行(可选,未测试但是应该能行):
46
+
47
+ 1. 安装依赖:`pip install -r requirements.txt`
48
+ 2. 设置环境变量(如上所述)。
49
+ 3. 运行:`uvicorn app.main:app --reload --host 0.0.0.0 --port 7860`
50
+
51
+ ### 1.8 💻 手机本地运行(可选,安装耗时长):
52
+
53
+ [Termux 安装与配置 Hajimi 项目教程 由**天命不又**编写](./Termux.md)
54
+
55
+ ### 1.9 💻 docker部署运行:
56
+
57
+ [docker 安装与配置 Hajimi 项目教程 由 **北极星星** 编写](./docker.md)
58
+
59
+ ### 1.10 🔌 接入其他服务
60
+
61
+ 1. 在连接中选择OpenAI
62
+ 2. 在API Base URL中填入`https://(huggingface用户名)-(huggingface项目名).hf.space/v1`
63
+ 3. 在API Key中填入`PASSWORD`环境变量的值,如未设置则填入`123`