Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def execute(self, model_id, prompt, negative_prompt, dialogue_number, dialogue_t
if isinstance(image_url, str):
if image_url.startswith('http'):
# HTTP URL 情况
image_url = requests.get(image_url).content
res = requests.get(image_url)
res.raise_for_status()
image_url = res.content
elif image_url.startswith('data:image'):
# Data URL 格式 (data:image/png;base64,...)
import base64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ def execute(self, model_id, prompt, negative_prompt, dialogue_number, dialogue_t
# 判断是不是 url
first_frame_url = self.get_file_base64(first_frame_url)
last_frame_url = self.get_file_base64(last_frame_url)
video_urls = ttv_model.generate_video(question, negative_prompt, first_frame_url, last_frame_url)
video_url = ttv_model.generate_video(question, negative_prompt, first_frame_url, last_frame_url)
# 保存图片
if video_urls is None or video_urls == '':
if video_url is None or video_url == '':
return NodeResult({'answer': gettext('Failed to generate video')}, {})
file_name = 'generated_video.mp4'
if isinstance(video_urls, str) and video_urls.startswith('http'):
video_urls = requests.get(video_urls).content
file = bytes_to_uploaded_file(video_urls, file_name)
if isinstance(video_url, str) and video_url.startswith('http'):
res = requests.get(video_url)
res.raise_for_status()
video_url = res.content
file = bytes_to_uploaded_file(video_url, file_name)
file_url = self.upload_file(file)
video_label = f'<video src="{file_url}" controls style="max-width: 100%; width: 100%; height: auto; max-height: 60vh;"></video>'
video_list = [{'file_id': file_url.split('/')[-1], 'file_name': file_name, 'url': file_url}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ def execute(self, model_id, prompt, negative_prompt, dialogue_number, dialogue_t
self.context['message_list'] = message_list
self.context['dialogue_type'] = dialogue_type
self.context['negative_prompt'] = self.generate_prompt_question(negative_prompt)
video_urls = ttv_model.generate_video(question, negative_prompt)
video_url = ttv_model.generate_video(question, negative_prompt)
# 保存图片
if video_urls is None:
if video_url is None:
return NodeResult({'answer': gettext('Failed to generate video')}, {})
file_name = 'generated_video.mp4'
if isinstance(video_urls, str) and video_urls.startswith('http'):
video_urls = requests.get(video_urls).content
file = bytes_to_uploaded_file(video_urls, file_name)
if isinstance(video_url, str) and video_url.startswith('http'):
res = requests.get(video_url)
res.raise_for_status()
video_url = res.content
file = bytes_to_uploaded_file(video_url, file_name)
file_url = self.upload_file(file)
video_label = f'<video src="{file_url}" controls style="max-width: 100%; width: 100%; height: auto;"></video>'
video_list = [{'file_id': file_url.split('/')[-1], 'file_name': file_name, 'url': file_url}]
Expand Down
6 changes: 4 additions & 2 deletions apps/application/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ def insert_template_workflow(self, instance: Dict):
download_url = work_flow_template.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
app = ApplicationSerializer(
data={'user_id': self.data.get('user_id'), 'workspace_id': self.data.get('workspace_id')}
).import_({
Expand All @@ -543,7 +544,7 @@ def insert_template_workflow(self, instance: Dict):
work_flow=work_flow
)
try:
requests.get(work_flow_template.get('downloadCallbackUrl'), timeout=5)
requests.get(work_flow_template.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")
return app
Expand Down Expand Up @@ -1145,6 +1146,7 @@ def update_template_workflow(self, instance: Dict, app: Application):
download_url = work_flow_template.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
try:
mk_instance = restricted_loads(res.content)
except Exception as e:
Expand Down Expand Up @@ -1194,7 +1196,7 @@ def update_template_workflow(self, instance: Dict, app: Application):
'auth_target_type': AuthTargetType.TOOL.value
}).auth_resource_batch([t.id for t in tool_model_list])
try:
requests.get(work_flow_template.get('downloadCallbackUrl'), timeout=5)
requests.get(work_flow_template.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")

Expand Down
1 change: 1 addition & 0 deletions apps/chat/views/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get(self, request: Request):
allow_redirects=True,
timeout=10
)
response.raise_for_status()
content_type = response.headers.get('Content-Type', '').split(';')[0]
# 创建Django流式响应
django_response = StreamingHttpResponse(
Expand Down
6 changes: 4 additions & 2 deletions apps/knowledge/serializers/knowledge_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,15 @@ def save_workflow(self, instance: Dict):
download_url = template_instance.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
KnowledgeWorkflowSerializer.Import(data={
'user_id': self.data.get('user_id'),
'workspace_id': self.data.get('workspace_id'),
'knowledge_id': str(knowledge_id),
}).import_({'file': bytes_to_uploaded_file(res.content, 'file.kbwf')}, is_import_tool=True)

try:
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5)
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")

Expand Down Expand Up @@ -523,14 +524,15 @@ def edit(self, instance: Dict):
download_url = template_instance.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
KnowledgeWorkflowSerializer.Import(data={
'user_id': self.data.get('user_id'),
'workspace_id': self.data.get('workspace_id'),
'knowledge_id': str(self.data.get('knowledge_id')),
}).import_({'file': bytes_to_uploaded_file(res.content, 'file.kbwf')}, is_import_tool=False)

try:
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5)
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def text_to_speech(self, text):
}
}
response = requests.post(api_url, headers=headers, json=payload)
response.raise_for_status()
audio_hex = response.json().get("output", {}).get("data", {}).get("audio")
if audio_hex:
audio = bytes.fromhex(audio_hex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,18 @@ def get_model_provide_info(self):
@staticmethod
def get_base_model_list(api_base):
base_url = get_base_url(api_base)
r = requests.request(method="GET", url=f"{base_url}/api/tags", timeout=5)
r.raise_for_status()
return r.json()
res = requests.request(method="GET", url=f"{base_url}/api/tags", timeout=5)
res.raise_for_status()
return res.json()

def down_model(self, model_type: str, model_name, model_credential: Dict[str, object]) -> Iterator[DownModelChunk]:
api_base = model_credential.get('api_base', '')
base_url = get_base_url(api_base)
r = requests.request(
res = requests.request(
method="POST",
url=f"{base_url}/api/pull",
data=json.dumps({"name": model_name}).encode(),
stream=True,
)
return convert(r)
res.raise_for_status()
return convert(res)
9 changes: 6 additions & 3 deletions apps/tools/serializers/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ def insert(self, instance, with_valid=True):
download_url = template_instance.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
tool = ToolSerializer.Import(data={
'file': bytes_to_uploaded_file(res.content, 'file.tool'),
'user_id': self.data.get('user_id'),
Expand All @@ -430,7 +431,7 @@ def insert(self, instance, with_valid=True):
}).import_(name=instance.get('name'), source='template')

try:
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5)
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")
return tool
Expand Down Expand Up @@ -1195,6 +1196,7 @@ def add(self, instance: Dict, with_valid=True):
(version.get('name') for version in versions if version.get('downloadUrl') == download_url),
)
res = requests.get(download_url, timeout=5)
res.raise_for_status()
tool_data = RestrictedUnpickler(io.BytesIO(res.content)).load().tool
tool_id = uuid.uuid7()
# 如果是SKILL类型的工具,保存文件内容到file表,并将code替换为file_id
Expand Down Expand Up @@ -1236,7 +1238,7 @@ def add(self, instance: Dict, with_valid=True):
'auth_target_type': AuthTargetType.TOOL.value
}).auth_resource(str(tool_id))
try:
requests.get(instance.get('download_callback_url'), timeout=5)
requests.get(instance.get('download_callback_url'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")
return ToolModelSerializer(tool).data
Expand All @@ -1262,6 +1264,7 @@ def update_tool(self, with_valid=True):
version.get('downloadUrl') == self.data.get('download_url')),
)
res = requests.get(self.data.get('download_url'), timeout=5)
res.raise_for_status()
tool_data = RestrictedUnpickler(io.BytesIO(res.content)).load().tool
# 如果是SKILL类型的工具,保存文件内容到file表,并将code替换为file_id
if tool_data.get('tool_type') == ToolType.SKILL:
Expand All @@ -1284,7 +1287,7 @@ def update_tool(self, with_valid=True):
# tool.is_active = False
tool.save()
try:
requests.get(self.data.get('download_callback_url'), timeout=5)
requests.get(self.data.get('download_callback_url'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")
return ToolModelSerializer(tool).data
Expand Down
3 changes: 2 additions & 1 deletion apps/tools/serializers/tool_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def edit(self, instance: Dict):
download_url = template_instance.get('downloadUrl')
# 查找匹配的版本名称
res = requests.get(download_url, timeout=5)
res.raise_for_status()
tool = QuerySet(Tool).filter(id=self.data.get("tool_id")).first()
ToolSerializer.Import(data={
'user_id': self.data.get('user_id'),
Expand All @@ -334,7 +335,7 @@ def edit(self, instance: Dict):
}).update_template_workflow(str(self.data.get('tool_id')))

try:
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5)
requests.get(template_instance.get('downloadCallbackUrl'), timeout=5).raise_for_status()
except Exception as e:
maxkb_logger.error(f"callback appstore tool download error: {e}")

Expand Down
Loading