2025-12-02 18:54:14 +08:00

34 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 变更:修复 DashScope 本地视频文件路径格式问题
## 原因
当前实现尝试使用本地文件路径调用 DashScope API但 API 返回错误:"The provided URL does not appear to be valid. Ensure it is correctly formatted."
根据 DashScope 官方文档示例,应该使用 `file://` 格式的本地文件路径:
```python
local_path = "xxx/test.mp4" # 绝对路径字符串
video_path = f"file://{local_path}"
```
当前代码虽然尝试了两种方式(直接路径和 file:// 格式),但都失败了。问题可能在于:
1. `file://` 格式的路径构造不正确(在 macOS/Linux 上应该是 `file://` 而不是 `file:///`
2. 路径中的特殊字符(如空格)没有进行 URL 编码
3. 路径格式不完全符合 DashScope SDK 的要求
需要严格按照官方文档示例实现,确保本地视频文件能够正确传递给 DashScope API。
## 变更内容
- 修改 `DashScopeService.analyze_video` 方法,严格按照 DashScope 文档示例使用 `file://{absolute_path}` 格式
- 确保路径格式正确:使用绝对路径字符串,然后添加 `file://` 前缀
- 处理路径中的特殊字符,确保路径格式符合 URL 规范
- 修改 `DashScopeService.compare_videos` 方法,使用相同的路径格式
- 移除不必要的回退逻辑,直接使用正确的格式
- 添加路径格式验证和错误处理
## 影响
- 受影响的规范:`specs/video-analysis/spec.md` - 需要更新视频分析实现要求
- 受影响的代码:
- `app/services/dashscope_service.py` - 修改视频路径格式处理逻辑
- 修复后视频分析、总结和对比功能可以正常工作
- 不影响视频上传和其他功能