feat: smart token routing for video generation + deviceEnvInfo fix #145
+112
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🎯 功能概述
实现了视频生成的智能 Token 路由功能,根据视频需求自动选择最合适的 Token 池(ssoSuper vs ssoBasic),并修复了视频分辨率不生效的问题。
🔧 主要改进
1. 智能 Token 路由 (
app/services/token/manager.py)新增
get_token_for_video()方法,根据视频配置智能选择 Token:ssoSuperTokenssoBasicToken解决的问题:非 SSO Super Token 请求 720p 视频时,Grok API 会静默降级到 480p。
2. 修复视频分辨率问题 (
app/services/grok/services/media.py)关键修复:添加缺失的
deviceEnvInfo字段问题根源:Grok API 后端需要
deviceEnvInfo来正确解析resolutionName。缺少此字段时,后端忽略分辨率参数,导致生成的视频分辨率不符合预期。修复效果:
3. 配置选项 (
config.defaults.toml)新增
[video]配置段:4. 测试文件
新增
test_video_token_routing.py单元测试,覆盖所有路由场景。📊 修改统计
✅ 测试结果
📝 使用示例
系统自动:
🔍 日志示例
🎉 总结
这个 PR 解决了两个问题:
两者结合,用户现在可以可靠地生成 720p 高清视频!