fix(multimodel): handle 302 redirect when downloading files

This commit is contained in:
Eternity
2026-03-13 16:46:03 +08:00
parent 85770dc037
commit 73aee97be5
2 changed files with 4 additions and 4 deletions

View File

@@ -75,7 +75,7 @@ class AudioTranscriptionService:
try: try:
# 下载音频文件 # 下载音频文件
async with httpx.AsyncClient(timeout=60.0) as client: async with httpx.AsyncClient(timeout=60.0) as client:
audio_response = await client.get(audio_url) audio_response = await client.get(audio_url, follow_redirects=True)
audio_response.raise_for_status() audio_response.raise_for_status()
audio_data = audio_response.content audio_data = audio_response.content

View File

@@ -130,7 +130,7 @@ class BedrockFormatStrategy(MultimodalFormatStrategy):
# 下载图片 # 下载图片
if content is None: if content is None:
async with httpx.AsyncClient(timeout=30.0) as client: async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(url) response = await client.get(url, follow_redirects=True)
response.raise_for_status() response.raise_for_status()
content = response.content content = response.content
self.file.set_content(content) self.file.set_content(content)
@@ -236,7 +236,7 @@ class OpenAIFormatStrategy(MultimodalFormatStrategy):
audio_data = content audio_data = content
if content is None: if content is None:
async with httpx.AsyncClient(timeout=30.0) as client: async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(url) response = await client.get(url, follow_redirects=True)
response.raise_for_status() response.raise_for_status()
audio_data = response.content audio_data = response.content
self.file.set_content(audio_data) self.file.set_content(audio_data)
@@ -566,7 +566,7 @@ class MultimodalService:
file_content = file.get_content() file_content = file.get_content()
if not file_content: if not file_content:
async with httpx.AsyncClient(timeout=30.0) as client: async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(file.url) response = await client.get(file.url, follow_redirects=True)
response.raise_for_status() response.raise_for_status()
file_content = response.content file_content = response.content
file.set_content(file_content) file.set_content(file_content)