{"id":35136162,"url":"https://github.com/wchiways/question-bank","last_synced_at":"2026-01-13T23:00:08.424Z","repository":{"id":330803513,"uuid":"1123571690","full_name":"wchiways/question-bank","owner":"wchiways","description":"基于 FastAPI + AsyncIO 的 OCS 题库查询系统，支持多个 AI 平台智能答题","archived":false,"fork":false,"pushed_at":"2026-01-02T08:32:16.000Z","size":455,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-13T22:59:46.439Z","etag":null,"topics":["ai","asyncio","fastapi","intelligent-answer","multiple-ai-providers","ocs","python","question-bank","quiz","sqlmodel"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wchiways.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-27T06:38:56.000Z","updated_at":"2026-01-04T07:49:16.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wchiways/question-bank","commit_stats":null,"previous_names":["wchiways/question-bank"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/wchiways/question-bank","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wchiways%2Fquestion-bank","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wchiways%2Fquestion-bank/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wchiways%2Fquestion-bank/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wchiways%2Fquestion-bank/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wchiways","download_url":"https://codeload.github.com/wchiways/question-bank/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wchiways%2Fquestion-bank/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28405148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","asyncio","fastapi","intelligent-answer","multiple-ai-providers","ocs","python","question-bank","quiz","sqlmodel"],"created_at":"2025-12-28T09:07:37.878Z","updated_at":"2026-01-13T23:00:08.412Z","avatar_url":"https://github.com/wchiways.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OCS题库系统 - FastAPI版本\n\n[![Python Version](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)\n[![FastAPI](https://img.shields.io/badge/FastAPI-0.127+-green.svg)](https://fastapi.tiangolo.com)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\u003e 基于 FastAPI + AsyncIO + SQLModel 的高性能题库查询系统\n\n## ✨ 特性\n\n- ✅ **异步架构**: 全链路异步处理，支持高并发\n- ✅ **类型安全**: 100%类型注解，Pydantic数据验证\n- ✅ **自动文档**: Swagger UI和ReDoc自动生成\n- ✅ **分层设计**: 清晰的分层架构，易于维护\n- ✅ **三级缓存**: 内存缓存 + 数据库 + AI服务\n- ✅ **智能重试**: AI调用失败自动重试\n- ✅ **多AI平台**: 支持硅基流动、阿里百炼、智谱AI、Google、OpenAI等多个平台\n\n## 📖 文档导航\n\n- [安装指南 (docs/INSTALL.md)](./docs/INSTALL.md) - 详细的安装和配置步骤\n- [Docker 部署 (docs/DOCKER.md)](./docs/DOCKER.md) - 容器化部署指南\n- [API 文档 (docs/API.md)](./docs/API.md) - 完整的 API 接口文档和使用示例\n- [开发指南 (docs/DEVELOPMENT.md)](./docs/DEVELOPMENT.md) - 项目架构、开发流程和编码规范\n\n## 👤 作者\n\n**Chiway Wang**\n- Email: [wchiway@163.com](mailto:wchiway@163.com)\n- Blog: [chiway.blog](https://chiway.blog)\n\n## 🛠️ 技术栈\n\n![Python](https://img.shields.io/badge/Python-3.11+-blue?logo=python)\n![FastAPI](https://img.shields.io/badge/FastAPI-0.127+-green?logo=fastapi)\n![SQLModel](https://img.shields.io/badge/SQLModel-Latest-orange?logo=sqlalchemy)\n\n- **Web框架**: FastAPI 0.127+\n- **ORM**: SQLModel (Pydantic + SQLAlchemy)\n- **数据库**: SQLite (aiosqlite异步驱动)\n- **HTTP客户端**: httpx (异步)\n- **日志**: loguru\n- **包管理**: uv\n\n## 📦 快速开始\n\n### 环境要求\n\n- Python 3.11+\n- uv (推荐) 或 pip\n\n### 安装\n\n```bash\n# 克隆项目\ngit clone https://github.com/wchiways/question-bank.git\ncd ocs-tiku\n\n# 使用uv (推荐)\nuv sync\n\n# 或使用pip\npip install -e .\n```\n\n### 配置\n\n复制配置文件模板：\n\n```bash\ncp config.example.json config.json\n```\n\n编辑`config.json`文件，配置你的AI服务：\n\n```json\n{\n  \"ai\": {\n    \"default_provider\": \"siliconflow\",\n    \"providers\": {\n      \"siliconflow\": {\n        \"enabled\": true,\n        \"api_key\": \"YOUR_API_KEY\"\n      },\n      \"ali_bailian\": {\n        \"enabled\": false,\n        \"api_key\": \"YOUR_ALI_BAILIAN_API_KEY\"\n      }\n    }\n  }\n}\n```\n\n**支持的AI平台**:\n- **硅基流动** (siliconflow) - 默认，性价比高\n- **阿里百炼** (ali_bailian) - 阿里云大模型平台\n- **智谱AI** (zhipu) - 清华KEG实验室\n- **Google Studio AI** (google) - Google Gemini\n- **OpenAI** (openai) - GPT系列模型\n\n### 运行\n\n```bash\n# 开发模式\nuv run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000\n\n# 或使用脚本\n./scripts/dev.sh\n```\n\n访问API文档：\n- Swagger UI: http://localhost:8000/docs\n- ReDoc: http://localhost:8000/redoc\n- 健康检查: http://localhost:8000/health\n\n### 部署方式 (Docker)\n\n如果你偏好使用容器化部署，请参考：\n👉 [Docker 部署指南 (docs/DOCKER.md)](./docs/DOCKER.md)\n\n```bash\n# 快速启动\ndocker compose up -d --build\n```\n\n## 📁 项目结构\n\n```\nocs-tiku/\n├── app/\n│   ├── api/              # API路由层\n│   │   ├── deps.py       # 依赖注入\n│   │   └── v1/           # API v1版本\n│   ├── core/             # 核心配置\n│   │   ├── config.py     # 配置管理\n│   │   ├── db.py         # 数据库连接\n│   │   └── logger.py     # 日志系统\n│   ├── models/           # 数据模型\n│   ├── schemas/          # Pydantic Schema\n│   ├── repositories/     # 数据访问层\n│   ├── services/         # 业务逻辑层\n│   └── providers/        # 外部服务提供商\n├── tests/                # 测试\n├── .env.example          # 环境变量模板\n├── pyproject.toml        # 项目配置\n└── README.md\n```\n\n## 🔌 API使用\n\n### 查询问题答案\n\n```bash\ncurl \"http://localhost:8000/api/v1/query?title=中国的首都是哪里？\u0026options=A.北京 B.上海\u0026type=single\"\n```\n\n响应：\n\n```json\n{\n  \"code\": 1,\n  \"data\": \"A.北京\",\n  \"msg\": \"AI回答\",\n  \"source\": \"ai\"\n}\n```\n\n### 🧩 OCS网课助手配置\n\n在油猴脚本或OCS软件中配置自定义题库：\n\n```json\n{\n    \"name\": \"OCS题库(FastAPI版)\",\n    \"homepage\": \"https://chiway.blog/\",\n    \"url\": \"http://localhost:8000/api/v1/query\",\n    \"method\": \"get\",\n    \"type\": \"GM_xmlhttpRequest\",\n    \"contentType\": \"json\",\n    \"data\": {\n        \"title\": \"${title}\",\n        \"options\": \"${options}\",\n        \"type\": \"${type}\"\n    },\n    \"handler\": \"return (res)=\u003eres.code === 0 ? [undefined, undefined] : [undefined, res.data]\"\n}\n```\n\n\u003e **注意**: `handler` 中必须使用 `res.data` 而不是 `res.data.data`，因为FastAPI版本的响应结构更加扁平。\n\n## 🧪 测试\n\n```bash\n# 运行测试\nuv run pytest tests/ -v\n\n# 查看覆盖率\nuv run pytest tests/ --cov=app --cov-report=html\n```\n\n## 📊 性能\n\n相比旧版Flask架构：\n\n| 指标 | Flask版本 | FastAPI版本 | 提升 |\n|------|----------|-------------|------|\n| 并发处理 | 4 QPS | 200+ QPS | **50倍** |\n| 响应时间 | ~100ms | \u003c50ms | **2倍** |\n| 代码量 | 239行 | 减少40% | 更简洁 |\n\n![Benchmark](https://img.shields.io/badge/Benchmark-50x%20Faster-brightgreen)\n\n## 🔄 从Flask迁移\n\n旧版本（Flask）保留在Git历史中。新版本（FastAPI）在`development`分支开发。\n\n迁移步骤：\n1. 备份数据库：`cp question_bank.db question_bank.db.backup`\n2. 安装新依赖：`uv sync`\n3. 配置AI服务：复制`config.example.json`为`config.json`并填入API密钥\n4. 启动新服务：`uv run uvicorn app.main:app`或`./scripts/dev.sh`\n\n## 📝 开发指南\n\n### 添加新的API端点\n\n1. 在`app/schemas/`定义请求/响应模型\n2. 在`app/api/v1/endpoints/`创建端点文件\n3. 在`app/api/v1/router.py`注册路由\n4. 添加相应的服务和仓储方法\n\n### 代码风格\n\n```bash\n# 格式化代码\nuv run black app/\n\n# 代码检查\nuv run ruff check app/\n```\n\n## 🤝 贡献\n\n欢迎提交 Issue 和 Pull Request！\n\n1. Fork 本仓库\n2. 创建特性分支 (`git checkout -b feature/AmazingFeature`)\n3. 提交更改 (`git commit -m 'feat: add some AmazingFeature'`)\n4. 推送到分支 (`git push origin feature/AmazingFeature`)\n5. 开启 Pull Request\n\n## 📄 许可证\n\n本项目采用 MIT 许可证 - 详见 [LICENSE](./LICENSE) 文件\n\n![License](https://img.shields.io/badge/License-MIT-blue.svg)\n\n## 🔗 相关链接\n\n- [FastAPI 文档](https://fastapi.tiangolo.com/)\n- [SQLModel 文档](https://sqlmodel.tiangolo.com/)\n- [uv 包管理器](https://github.com/astral-sh/uv)\n\n## 🌟 Star History\n\n如果这个项目对你有帮助，请给它一个 Star！\n\n## 🎉 致谢\n\n- [FastAPI](https://fastapi.tiangolo.com/)\n- [SQLModel](https://sqlmodel.tiangolo.com/)\n- [uv](https://github.com/astral-sh/uv)\n- 原项目：[ai-ocs-question_bank](https://github.com/Miaozeqiu/ai-ocs-question_bank) by Miaozeqiu\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwchiways%2Fquestion-bank","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwchiways%2Fquestion-bank","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwchiways%2Fquestion-bank/lists"}