Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/incorrect code template #7490

Merged
merged 3 commits into from
Aug 21, 2024
Merged
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
6 changes: 3 additions & 3 deletions api/core/helper/code_executor/code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from threading import Lock
from typing import Literal, Optional

from httpx import get, post
from httpx import Timeout, get, post
from pydantic import BaseModel
from yarl import URL

Expand All @@ -21,7 +21,7 @@
CODE_EXECUTION_ENDPOINT = dify_config.CODE_EXECUTION_ENDPOINT
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):
pass
Expand Down Expand Up @@ -116,7 +116,7 @@ def execute_code(cls,
if response.data.error:
raise CodeExecutionException(response.data.error)

return response.data.stdout
return response.data.stdout or ''

@classmethod
def execute_workflow_code_template(cls, language: CodeLanguage, code: str, inputs: dict, dependencies: Optional[list[CodeDependency]] = None) -> dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def get_language() -> str:
def get_default_code(cls) -> str:
return dedent(
"""
def main(arg1: int, arg2: int) -> dict:
def main(arg1: str, arg2: str) -> dict:
return {
"result": arg1 + arg2,
}
Expand Down
5 changes: 2 additions & 3 deletions api/core/workflow/nodes/code/code_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class CodeNode(BaseNode):
_node_data_cls = CodeNodeData
node_type = NodeType.CODE
_node_type = NodeType.CODE

@classmethod
def get_default_config(cls, filters: Optional[dict] = None) -> dict:
Expand All @@ -48,8 +48,7 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult:
:param variable_pool: variable pool
:return:
"""
node_data = self.node_data
node_data: CodeNodeData = cast(self._node_data_cls, node_data)
node_data = cast(CodeNodeData, self.node_data)

# Get code language
code_language = node_data.code_language
Expand Down