mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 19:36:53 +08:00
feat: mypy for all type check (#10921)
This commit is contained in:
@@ -38,7 +38,7 @@ class CodeLanguage(StrEnum):
|
||||
|
||||
|
||||
class CodeExecutor:
|
||||
dependencies_cache = {}
|
||||
dependencies_cache: dict[str, str] = {}
|
||||
dependencies_cache_lock = Lock()
|
||||
|
||||
code_template_transformers: dict[CodeLanguage, type[TemplateTransformer]] = {
|
||||
@@ -103,19 +103,19 @@ class CodeExecutor:
|
||||
)
|
||||
|
||||
try:
|
||||
response = response.json()
|
||||
response_data = response.json()
|
||||
except:
|
||||
raise CodeExecutionError("Failed to parse response")
|
||||
|
||||
if (code := response.get("code")) != 0:
|
||||
raise CodeExecutionError(f"Got error code: {code}. Got error msg: {response.get('message')}")
|
||||
if (code := response_data.get("code")) != 0:
|
||||
raise CodeExecutionError(f"Got error code: {code}. Got error msg: {response_data.get('message')}")
|
||||
|
||||
response = CodeExecutionResponse(**response)
|
||||
response_code = CodeExecutionResponse(**response_data)
|
||||
|
||||
if response.data.error:
|
||||
raise CodeExecutionError(response.data.error)
|
||||
if response_code.data.error:
|
||||
raise CodeExecutionError(response_code.data.error)
|
||||
|
||||
return response.data.stdout or ""
|
||||
return response_code.data.stdout or ""
|
||||
|
||||
@classmethod
|
||||
def execute_workflow_code_template(cls, language: CodeLanguage, code: str, inputs: Mapping[str, Any]):
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from collections.abc import Mapping
|
||||
|
||||
from core.helper.code_executor.code_executor import CodeExecutor, CodeLanguage
|
||||
|
||||
|
||||
class Jinja2Formatter:
|
||||
@classmethod
|
||||
def format(cls, template: str, inputs: dict) -> str:
|
||||
def format(cls, template: str, inputs: Mapping[str, str]) -> str:
|
||||
"""
|
||||
Format template
|
||||
:param template: template
|
||||
@@ -11,5 +13,4 @@ class Jinja2Formatter:
|
||||
:return:
|
||||
"""
|
||||
result = CodeExecutor.execute_workflow_code_template(language=CodeLanguage.JINJA2, code=template, inputs=inputs)
|
||||
|
||||
return result["result"]
|
||||
return str(result.get("result", ""))
|
||||
|
||||
@@ -29,8 +29,7 @@ class TemplateTransformer(ABC):
|
||||
result = re.search(rf"{cls._result_tag}(.*){cls._result_tag}", response, re.DOTALL)
|
||||
if not result:
|
||||
raise ValueError("Failed to parse result")
|
||||
result = result.group(1)
|
||||
return result
|
||||
return result.group(1)
|
||||
|
||||
@classmethod
|
||||
def transform_response(cls, response: str) -> Mapping[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user