itismygo
300b03fdde
fix: 修复 grok-imagine-0.9 纯文本生成图片的bug
## 问题描述
当使用 grok-imagine-0.9 模型进行纯文本到图片生成时,会抛出 "list index out of range" 错误。
## 根本原因
1. **模型配置错误**: grok-imagine-0.9 被错误地标记为视频模型 (`is_video_model: True`)
2. **数组访问bug**: 在没有图片附件时,代码尝试访问空列表的第一个元素 `payload.get("fileAttachments", [""])[0]`
## 修复内容
### app/models/grok_models.py
- 将 `is_video_model` 从 `True` 改为 `False`
- 更新 description 为 "Image generation model powered by Grok"
### app/services/grok/client.py
- 修复空列表访问bug,使用安全的访问方式:
```python
file_attachments = payload.get("fileAttachments", [])
ref_id = post_id or (file_attachments[0] if file_attachments else "")
```
## 测试结果
✅ 纯文本生成图片:成功
✅ 文本对话:正常
✅ 其他模型:不受影响
## 相关信息
根据 xAI 官方文档,Grok Imagine 主要是图像生成模型(使用 Aurora 引擎),支持 text-to-image 功能。