Skip to content

Commit 2f26d2b

Browse files
committed
refactor: split manager.py, unify models/constants, fix proxy SSL error storm
Stage 1: Structure refactor + cleanup - Split manager.py (844 lines) into manager/ package with APIRouter - Unify Pydantic models into models/types.py (remove duplicates from gateway.py, routes.py) - Unify path constants (use config.settings instead of redefinition) - Fix gateway.py deprecated @app.on_event -> lifespan - Remove llm/ directory (unused Flask Ollama mock) - Fix Pydantic validation_alias warning -> model_validator Stage 2: MITM Proxy runtime fixes - Expand SSL error filter (3 -> 10 keywords, including Windows CJK errors) - Fix chunk parse bug: strip HTTP headers before unchunking - Fix asyncio task leak: proper cancel in _run_relay_tasks - Set asyncio logger to ERROR (suppress eof_received warnings) - Remove dead code: create_logger, check_generate_endpoint, _configure_logging - Unify logging.basicConfig in runner.py
1 parent 9cda548 commit 2f26d2b

31 files changed

Lines changed: 2354 additions & 2035 deletions

README.md

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
- **智能模型切换**: 通过 `model` 字段动态切换 AI Studio 中的模型
4242
- **反指纹检测**: 使用 Camoufox 浏览器降低被检测风险
4343
- **图形界面启动器**: 功能丰富的 **网页** 启动器,简化配置和管理
44-
- **Ollama 兼容层**: 内置 `llm.py` 提供 Ollama 格式 API 兼容
4544
- **模块化架构**: 清晰的模块分离设计,易于维护
4645
- **现代化工具链**: uv 依赖管理 + 完整类型支持
4746

@@ -304,21 +303,6 @@ curl -X POST http://localhost:2048/nano/generate \
304303

305304
**详细文档**: 参见 [媒体生成指南](docs/media-generation-guide.md)
306305

307-
### Ollama 兼容层
308-
309-
项目还提供 Ollama 格式的 API 兼容:
310-
311-
```bash
312-
# 启动 Ollama 兼容服务
313-
uv run python src/app_launcher.py
314-
# 在 GUI 的配置页面中点击"启动本地LLM模拟服务"
315-
316-
# 使用 Ollama 格式 API
317-
curl http://localhost:11434/api/tags
318-
curl -X POST http://localhost:11434/api/chat \
319-
-d '{"model": "gemini", "messages": [{"role": "user", "content": "Hello"}]}'
320-
```
321-
322306
## 🏗️ 项目架构
323307

324308
```
@@ -327,7 +311,7 @@ AIStudio2API/
327311
│ ├── app_launcher.py # 图形界面启动器
328312
│ ├── launch_camoufox.py # 命令行启动器
329313
│ ├── server.py # 主服务器
330-
│ ├── manager.py # WebUI 管理器
314+
│ ├── manager/ # WebUI 管理器包
331315
│ ├── api/ # API 处理模块
332316
│ ├── browser/ # 浏览器自动化模块
333317
│ ├── config/ # 配置管理
@@ -342,7 +326,6 @@ AIStudio2API/
342326
│ ├── auth_profiles/ # 认证文件
343327
│ ├── certs/ # 证书文件
344328
│ └── key.txt # API 密钥
345-
├── llm/ # Ollama 兼容层
346329
├── camoufox/ # Camoufox 脚本
347330
├── docker/ # Docker 配置
348331
├── docs/ # 详细文档
@@ -369,7 +352,6 @@ cp .env.example .env
369352
- **FastAPI 服务**: 默认端口 `2048`
370353
- **Camoufox 调试**: 默认端口 `9222`
371354
- **流式代理**: 默认端口 `3120`
372-
- **Ollama 兼容**: 默认端口 `11434`
373355

374356
## 🔧 高级功能
375357

@@ -460,4 +442,4 @@ netsh int ipv4 add excludedportrange protocol=tcp startport=3000 numberofports=2
460442
- **Go 语言重构**: 将核心代理服务迁移至 Go 以提升并发性能与降低资源占用
461443
- **CI/CD 流水线**: 建立 GitHub Actions 自动化测试与构建发布流程
462444
- **单元测试**: 增加核心模块(特别是浏览器自动化部分)的测试覆盖率
463-
-**多Worker负载均衡**: 支持多 Google 账号轮询池,提高并发限额与稳定性 (这项或许不可能实现) (fix:2025/12/09 这项已实现)
445+
-**多Worker负载均衡**: 支持多 Google 账号轮询池,提高并发限额与稳定性 (这项或许不可能实现) (fix:2025/12/09 这项已实现)

README_en.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
- **Smart Model Switching**: Dynamically switch models in AI Studio via the `model` field
4242
- **Anti-Fingerprint Detection**: Uses Camoufox browser to reduce detection risk
4343
- **GUI Launcher**: Feature-rich **web** launcher for simplified configuration and management
44-
- **Ollama Compatibility Layer**: Built-in `llm.py` provides Ollama format API compatibility
4544
- **Modular Architecture**: Clear module separation design for easy maintenance
4645
- **Modern Toolchain**: uv dependency management + full type support
4746

@@ -298,21 +297,6 @@ curl -X POST http://localhost:2048/nano/generate \
298297

299298
**Detailed Documentation**: See [Media Generation Guide](docs/media-generation-guide.md)
300299

301-
### Ollama Compatibility Layer
302-
303-
The project also provides Ollama format API compatibility:
304-
305-
```bash
306-
# Start Ollama compatible service
307-
uv run python src/app_launcher.py
308-
# Click "Start Local LLM Simulation Service" in the GUI config page
309-
310-
# Use Ollama format API
311-
curl http://localhost:11434/api/tags
312-
curl -X POST http://localhost:11434/api/chat \
313-
-d '{"model": "gemini", "messages": [{"role": "user", "content": "Hello"}]}'
314-
```
315-
316300
## 🏗️ Project Architecture
317301

318302
```
@@ -321,7 +305,7 @@ AIStudio2API/
321305
│ ├── app_launcher.py # GUI launcher
322306
│ ├── launch_camoufox.py # Command-line launcher
323307
│ ├── server.py # Main server
324-
│ ├── manager.py # WebUI manager
308+
│ ├── manager/ # WebUI manager package
325309
│ ├── api/ # API processing modules
326310
│ ├── browser/ # Browser automation modules
327311
│ ├── config/ # Configuration management
@@ -336,7 +320,6 @@ AIStudio2API/
336320
│ ├── auth_profiles/ # Authentication files
337321
│ ├── certs/ # Certificate files
338322
│ └── key.txt # API keys
339-
├── llm/ # Ollama compatibility layer
340323
├── camoufox/ # Camoufox scripts
341324
├── docker/ # Docker configuration
342325
├── docs/ # Detailed documentation
@@ -363,7 +346,6 @@ cp .env.example .env
363346
- **FastAPI Service**: Default port `2048`
364347
- **Camoufox Debug**: Default port `9222`
365348
- **Streaming Proxy**: Default port `3120`
366-
- **Ollama Compatible**: Default port `11434`
367349

368350
## 🔧 Advanced Features
369351

@@ -455,4 +437,3 @@ Issues and Pull Requests are welcome!
455437
- **CI/CD Pipeline**: Establish GitHub Actions automated testing and build release process
456438
- **Unit Testing**: Increase test coverage for core modules (especially browser automation)
457439
-**Multi-Worker Load Balancing**: Support multi-Google account rotation pool for higher concurrency limits
458-

docs/api-usage.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,6 @@ curl -X POST http://localhost:2048/generate-speech \
275275

276276
**详细文档**: 参见 [媒体生成指南](media-generation-guide.md)
277277

278-
### Ollama 兼容层
279-
280-
项目还提供 Ollama 格式的 API 兼容:
281-
282-
```bash
283-
# 启动 Ollama 兼容服务
284-
uv run python app_launcher.py
285-
# 在 GUI 的配置页面中点击"启动本地LLM模拟服务"
286-
287-
# 使用 Ollama 格式 API
288-
curl http://localhost:11434/api/tags
289-
curl -X POST http://localhost:11434/api/chat \
290-
-d '{"model": "gemini", "messages": [{"role": "user", "content": "Hello"}]}'
291-
```
292-
293278
### 模型列表
294279

295280
**端点**: `GET /v1/models`

docs/development-guide.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ AIStudio2API/
8181
│ ├── static/ # 静态资源
8282
│ ├── app_launcher.py # GUI 启动器
8383
│ ├── launch_camoufox.py # 命令行启动器
84-
│ ├── manager.py # WebUI 管理器
84+
│ ├── manager/ # WebUI 管理器包
8585
│ ├── gateway.py # 多Worker负载均衡网关
8686
│ └── server.py # 主服务器
8787
├── data/ # 运行时数据目录
8888
│ ├── auth_profiles/ # 认证文件存储
8989
│ ├── certs/ # 代理证书
9090
│ └── key.txt # API 密钥
91-
├── llm/ # Ollama 兼容层
9291
├── camoufox/ # Camoufox 脚本
9392
├── docker/ # Docker 相关文件
9493
├── docs/ # 文档目录

docs/project-structure.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ AIStudio2API 是一个高性能代理服务,将 Google AI Studio 网页界面
3333
| `app_launcher.py` | **图形界面启动器**。启动 WebUI 管理服务 (端口9000),自动打开浏览器 Dashboard |
3434
| `launch_camoufox.py` | **命令行启动器**。核心启动脚本,处理 Camoufox 浏览器启动、认证管理、代理配置、流式代理等 |
3535
| `server.py` | **主服务器**。定义全局状态变量,创建 FastAPI 应用实例,挂载静态资源 |
36-
| `manager.py` | **WebUI 管理器**处理 Dashboard API、服务启停、认证文件管理、多 Worker 管理 |
36+
| `manager/` | **WebUI 管理器包**拆分服务管理、应用工厂与 Dashboard API 路由 |
3737
| `gateway.py` | **多 Worker 网关**。负载均衡代理,将请求分发到多个 Worker 实例 |
3838

3939
---
@@ -160,14 +160,6 @@ AIStudio2API 是一个高性能代理服务,将 Google AI Studio 网页界面
160160

161161
---
162162

163-
## llm/ - Ollama 兼容层
164-
165-
| 文件 | 描述 |
166-
|------|------|
167-
| `llm.py` | Ollama 格式 API 兼容层,转发请求到主服务 |
168-
169-
---
170-
171163
## camoufox/ - Camoufox 脚本
172164

173165
| 文件 | 描述 |

llm/llm.py

Lines changed: 0 additions & 179 deletions
This file was deleted.

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ dependencies = [
1919
"aiohttp>=3.9.5",
2020
"requests==2.31.0",
2121
"pyjwt==2.8.0",
22-
"Flask==3.0.3",
2322
"aiosocks~=0.2.6",
2423
"python-socks~=2.7.1"
2524
]

0 commit comments

Comments
 (0)