feat: mypy for all type check (#10921)

This commit is contained in:
yihong
2024-12-24 18:38:51 +08:00
committed by GitHub
parent c91e8b1737
commit 56e15d09a9
584 changed files with 3975 additions and 2826 deletions

View File

@@ -1,4 +1,5 @@
import base64
from collections.abc import Mapping
from configs import dify_config
from core.helper import ssrf_proxy
@@ -55,7 +56,7 @@ def to_prompt_message_content(
if f.type == FileType.IMAGE:
params["detail"] = image_detail_config or ImagePromptMessageContent.DETAIL.LOW
prompt_class_map = {
prompt_class_map: Mapping[FileType, type[MultiModalPromptMessageContent]] = {
FileType.IMAGE: ImagePromptMessageContent,
FileType.AUDIO: AudioPromptMessageContent,
FileType.VIDEO: VideoPromptMessageContent,
@@ -63,7 +64,7 @@ def to_prompt_message_content(
}
try:
return prompt_class_map[f.type](**params)
return prompt_class_map[f.type].model_validate(params)
except KeyError:
raise ValueError(f"file type {f.type} is not supported")