feat: add support for audio and video input via base64

This commit adds configuration and conversion logic to handle audio and video inputs in base64 format, similar to existing image support. It includes:

1. Added supported formats and size limits in config
2. Implemented media validation and conversion in message converter
3. Updated payload building to handle media parts
4. Improved error handling and logging for media processing
This commit is contained in:
Your Name (aider)
2025-04-26 03:07:54 +00:00
parent cb40848c04
commit 775930edce
3 changed files with 253 additions and 6 deletions
+24
View File
@@ -69,6 +69,12 @@ class Settings(BaseSettings):
# 日志配置
LOG_LEVEL: str = "INFO" # 默认日志级别
# Audio/Video Settings
SUPPORTED_AUDIO_FORMATS: List[str] = ["wav", "mp3", "flac", "ogg"] # Add formats Gemini supports
SUPPORTED_VIDEO_FORMATS: List[str] = ["mp4", "mov", "avi", "webm"] # Add formats Gemini supports
MAX_AUDIO_SIZE_BYTES: int = 50 * 1024 * 1024 # Example: 50MB limit for Base64 payload
MAX_VIDEO_SIZE_BYTES: int = 200 * 1024 * 1024 # Example: 200MB limit
def __init__(self, **kwargs):
super().__init__(**kwargs)
# 设置默认AUTH_TOKEN(如果未提供)
@@ -78,6 +84,24 @@ class Settings(BaseSettings):
# 创建全局配置实例
settings = Settings()
# Optional: Define MIME type mappings if needed, or handle directly in converter
AUDIO_FORMAT_TO_MIMETYPE = {
"wav": "audio/wav",
"mp3": "audio/mpeg",
"flac": "audio/flac",
"ogg": "audio/ogg",
# Add other mappings supported by Gemini
}
VIDEO_FORMAT_TO_MIMETYPE = {
"mp4": "video/mp4",
"mov": "video/quicktime",
"avi": "video/x-msvideo",
"webm": "video/webm",
# Add other mappings supported by Gemini
}
def _parse_db_value(key: str, db_value: str, target_type: Type) -> Any:
"""尝试将数据库字符串值解析为目标 Python 类型"""
from app.log.logger import get_config_logger # 函数内导入