mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Fix/incorrect code template (#7490)
This commit is contained in:
parent
85fc0fdb51
commit
a02118d5bc
|
@ -4,7 +4,7 @@ from enum import Enum
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
|
|
||||||
from httpx import get, post
|
from httpx import Timeout, get, post
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from yarl import URL
|
from yarl import URL
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
|
||||||
CODE_EXECUTION_ENDPOINT = dify_config.CODE_EXECUTION_ENDPOINT
|
CODE_EXECUTION_ENDPOINT = dify_config.CODE_EXECUTION_ENDPOINT
|
||||||
CODE_EXECUTION_API_KEY = dify_config.CODE_EXECUTION_API_KEY
|
CODE_EXECUTION_API_KEY = dify_config.CODE_EXECUTION_API_KEY
|
||||||
|
|
||||||
CODE_EXECUTION_TIMEOUT = (10, 60)
|
CODE_EXECUTION_TIMEOUT = Timeout(connect=10, write=10, read=60, pool=None)
|
||||||
|
|
||||||
class CodeExecutionException(Exception):
|
class CodeExecutionException(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -116,7 +116,7 @@ class CodeExecutor:
|
||||||
if response.data.error:
|
if response.data.error:
|
||||||
raise CodeExecutionException(response.data.error)
|
raise CodeExecutionException(response.data.error)
|
||||||
|
|
||||||
return response.data.stdout
|
return response.data.stdout or ''
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def execute_workflow_code_template(cls, language: CodeLanguage, code: str, inputs: dict, dependencies: Optional[list[CodeDependency]] = None) -> dict:
|
def execute_workflow_code_template(cls, language: CodeLanguage, code: str, inputs: dict, dependencies: Optional[list[CodeDependency]] = None) -> dict:
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Python3CodeProvider(CodeNodeProvider):
|
||||||
def get_default_code(cls) -> str:
|
def get_default_code(cls) -> str:
|
||||||
return dedent(
|
return dedent(
|
||||||
"""
|
"""
|
||||||
def main(arg1: int, arg2: int) -> dict:
|
def main(arg1: str, arg2: str) -> dict:
|
||||||
return {
|
return {
|
||||||
"result": arg1 + arg2,
|
"result": arg1 + arg2,
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ MAX_NUMBER_ARRAY_LENGTH = dify_config.CODE_MAX_NUMBER_ARRAY_LENGTH
|
||||||
|
|
||||||
class CodeNode(BaseNode):
|
class CodeNode(BaseNode):
|
||||||
_node_data_cls = CodeNodeData
|
_node_data_cls = CodeNodeData
|
||||||
node_type = NodeType.CODE
|
_node_type = NodeType.CODE
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_default_config(cls, filters: Optional[dict] = None) -> dict:
|
def get_default_config(cls, filters: Optional[dict] = None) -> dict:
|
||||||
|
@ -48,8 +48,7 @@ class CodeNode(BaseNode):
|
||||||
:param variable_pool: variable pool
|
:param variable_pool: variable pool
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
node_data = self.node_data
|
node_data = cast(CodeNodeData, self.node_data)
|
||||||
node_data: CodeNodeData = cast(self._node_data_cls, node_data)
|
|
||||||
|
|
||||||
# Get code language
|
# Get code language
|
||||||
code_language = node_data.code_language
|
code_language = node_data.code_language
|
||||||
|
|
Loading…
Reference in New Issue
Block a user