Skip to content

Sonder9999/RainClassroomAssitant

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RainClassroomAssitant

基于 Python 的雨课堂辅助工具。当前仓库在原有“课程监听、自动签到、自动答题、自动弹幕、语音提醒”基础上,增加了面向 OpenAI 兼容接口的大模型答题链路,并支持多模型配置切换。

免责声明

  • 本项目仅用于学习研究、接口分析、自动化测试与个人技术实践。
  • 请自行评估使用风险,并遵守学校、课程平台、课堂纪律与相关法律法规。
  • 仓库中不应提交任何真实的 sessionid、API Key、Bearer Token 等敏感信息。
  • 雨课堂内部接口与字段不是官方稳定公开文档,可能随时变更。

当前能力

  • 自动检测正在上课的课程并加入监听
  • 自动签到并建立课堂 WebSocket 连接
  • 监听新题事件并刷新题目缓存
  • 优先直取题图,失败时回退到文本模式
  • 调用 OpenAI 兼容大模型并强制要求返回 JSON
  • 自动提交单选、多选、填空答案
  • 自动弹幕
  • 语音提醒
    • 题目出现时播报一次题干摘要
    • AI 成功或失败时再播报一次结果
  • 运行日志自动落盘到本地

项目结构

RainClassroomAssitant/
├─ RainClassroomAssistant.py
├─ README.md
├─ requirements.txt
├─ config.ai.json.example
├─ Scripts/
│  ├─ Monitor.py
│  ├─ Classes.py
│  ├─ Utils.py
│  ├─ app_config.py
│  ├─ openai_compatible_client.py
│  ├─ siliconflow_client.py
│  ├─ ai_pipeline.py
│  ├─ answer_executor.py
│  ├─ question_monitor.py
│  ├─ question_capture.py
│  ├─ screenshot_provider.py
│  ├─ lesson_support.py
│  ├─ event_logger.py
│  ├─ runtime_logging.py
│  └─ verification_report.py
├─ UI/
│  ├─ MainWindow.py
│  ├─ Login.py
│  ├─ Config.py
│  └─ Image/
├─ docs/
│  └─ ui-ai-handoff.md
└─ tests/

核心架构

1. 课堂监听

  • Monitor.py 负责轮询当前上课课程
  • Classes.py 为每门课建立签到、WebSocket、题目缓存、答题提交流程

2. 题目标准化与捕获

  • question_monitor.py
    • 标准化题目结构
    • 统一输出 question_idquestion_type_hintstem_textoption_textsblank_count
  • question_capture.py
    • 优先提取原图 URL 并下载
    • 无图时允许文本模式
    • 截图兜底通过 screenshot_provider.py 接入

3. 大模型调用

  • openai_compatible_client.py
    • 使用 OpenAI 兼容 /chat/completions 接口
    • 支持 SiliconFlow、RightCode 及其他兼容网关
    • 不支持 response_format=json_object 时会自动降级重试
  • siliconflow_client.py
    • 兼容旧导入路径的薄封装

4. 执行与日志

  • answer_executor.py 负责整理提交 payload、重试与 dry-run
  • runtime_logging.py 负责把 UI 输出写入本地日志文件
  • lesson_support.py 负责题目摘要和语音播报文案

配置说明

项目存在两套配置。

1. 主程序配置

位置:

  • %APPDATA%\\RainClassroomAssistant\\config.json

主要包含:

  • sessionid
  • auto_answer
  • 弹幕配置
  • 语音配置

2. AI 配置

搜索优先级:

  1. 项目根目录的 config.ai.json
  2. 环境变量 RAIN_AI_CONFIG_PATH
  3. %APPDATA%\\RainClassroomAssistant\\ai_config.json

建议复制 config.ai.json.example 为项目根目录的 config.ai.json

AI 配置结构

当前使用“多 profile + 一个激活项 + 一组共享参数”的结构:

{
  "enabled": true,
  "dry_run": false,
  "active_profile": "rightcode",
  "profiles": {
    "rightcode": {
      "api_key": "YOUR_API_KEY",
      "base_url": "https://right.codes/codex/v1",
      "model": "gpt-5.4",
      "timeout_sec": 30
    },
    "siliconflow": {
      "api_key": "YOUR_API_KEY",
      "base_url": "https://api.siliconflow.cn/v1",
      "model": "Qwen/Qwen2.5-VL-72B-Instruct",
      "timeout_sec": 30
    }
  },
  "shared": {
    "vision_prompt": {
      "system": "...",
      "user_template": "..."
    },
    "capture": {
      "prefer_direct_image": true,
      "enable_screenshot_fallback": true,
      "download_timeout_sec": 10,
      "render_wait_ms": 1200,
      "retry_times": 2,
      "screenshot": {
        "enabled": false,
        "url_template": "",
        "selector_candidates": [
          ".problem-box",
          ".problem",
          ".exercise-box"
        ],
        "timeout_ms": 5000,
        "output_dir": "tmp/screenshots"
      }
    },
    "answering": {
      "submit_delay_sec": 2,
      "json_retry_times": 2,
      "request_retry_times": 2
    }
  }
}

关键字段:

  • enabled
    • 是否启用 AI 答题链路
  • dry_run
    • 只识别不提交
  • active_profile
    • 当前实际使用的模型配置名
  • profiles
    • 多套模型连接配置
  • shared.vision_prompt
    • 对所有 profile 共用的 Prompt
  • shared.capture
    • 题图获取、截图兜底参数
  • shared.answering
    • 提交延迟、请求重试等参数

UI 配置页

当前 Config.py 已把 AI 配置放在最前面,支持:

  • 启用/禁用 AI
  • dry_run
  • 新增 profile
  • 删除 profile
  • 切换当前激活 profile
  • 编辑当前 profile 的:
    • API Key
    • Base URL
    • Model
    • Timeout
  • 编辑共享配置:
    • Prompt
    • 图片捕获
    • 截图兜底
    • 重试次数

后续如果要继续改 UI,请先看 ui-ai-handoff.md。

运行日志

程序启动后,UI 中所有日志会同步写入:

  • %APPDATA%\\RainClassroomAssistant\\logs\\YYYY-MM-DD.log

用途:

  • 程序被直接关闭后仍可回看日志
  • 方便排查题目事件顺序、接口失败、模型返回格式问题

语音播报策略

当前语音策略已经收敛,不再播报过多技术细节:

  • 题目出现时:播报一次题干摘要
  • AI 成功时:播报一次成功
  • AI 失败时:播报一次失败

不会再播报:

  • problemId
  • 答案数组
  • 接口调试字段

已使用或已观测到的接口

雨课堂 HTTP

接口 方法 用途
https://www.yuketang.cn/api/v3/user/basic-info GET 获取当前登录用户信息
https://www.yuketang.cn/api/v3/classroom/on-lesson GET 获取当前上课课程列表
https://www.yuketang.cn/api/v3/lesson/checkin POST 课堂签到并拿到 Set-Auth
https://www.yuketang.cn/api/v3/lesson/basic-info GET 获取课程标题、教师、开始时间
https://www.yuketang.cn/api/v3/lesson/presentation/fetch?presentation_id=... GET 获取课件与题目缓存
https://www.yuketang.cn/api/v3/lesson/problem/answer POST 提交答案
https://www.yuketang.cn/api/v3/lesson/danmu/send POST 发送弹幕
https://www.yuketang.cn/v/course_meta/fetch_user_info_new?... GET 获取弹幕发送者信息

雨课堂 WebSocket

  • 地址:wss://www.yuketang.cn/wsapp/

主要事件:

  • hello
  • unlockproblem
  • probleminfo
  • presentationupdated
  • presentationcreated
  • newdanmu
  • callpaused
  • lessonfinished

OpenAI 兼容模型接口

当前统一走:

  • POST <base_url>/chat/completions

已验证可用于:

  • SiliconFlow
  • RightCode
  • 其他 OpenAI 兼容网关

联调中确认过的关键点

  • problemId 必须以字符串提交,不能转成整数
  • problemType 必须是数字
  • result 必须是数组
  • dt 必须是毫秒时间戳
  • unlockproblem 到来后必须先刷新题目缓存
  • “无图”不等于“不能识别”,文本模式必须作为兜底
  • Prompt 渲染不能直接对 JSON 示例使用 str.format()

运行方式

安装依赖:

pip install -r requirements.txt

如果要启用截图兜底:

pip install playwright
playwright install

启动程序:

python .\RainClassroomAssistant.py

常用验证命令

python -m unittest discover -s tests -v
python -m compileall Scripts UI RainClassroomAssistant.py
python .\tests\poc_siliconflow.py tests\fixtures\sample_choice.png --config config.ai.json

已知限制

  • 截图兜底已接入,但默认关闭
  • 当前主要验证的是选择题、填空题链路
  • 主观题尚未做完整自动作答
  • 旧逻辑与新 AI 链路仍处于混合结构

参考链接

雨课堂

SiliconFlow

参考实现

About

基于 Python 的雨课堂辅助工具,支持 AI 视觉答题、自动签到、课堂监听与自动弹幕

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 100.0%