Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: correct behaviour of code fix (#24152)

Streamc2606f9062f9
diff --git a/api/controllers/console/app/generator.py b/api/controllers/console/app/generator.py
index 1cabfd9f2e5..57dc1267d55 100644
--- a/api/controllers/console/app/generator.py
+++ b/api/controllers/console/app/generator.py
@@ -12,7 +12,6 @@ from controllers.console.app.error import (
)
from controllers.console.wraps import account_initialization_required, setup_required
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
-from core.helper.code_executor.code_node_provider import CodeNodeProvider
from core.helper.code_executor.javascript.javascript_code_provider import JavascriptCodeProvider
from core.helper.code_executor.python3.python3_code_provider import Python3CodeProvider
from core.llm_generator.llm_generator import LLMGenerator
@@ -126,11 +125,13 @@ class InstructionGenerateApi(Resource):
parser.add_argument("model_config", type=dict, required=True, nullable=False, location="json")
parser.add_argument("ideal_output", type=str, required=False, default="", location="json")
args = parser.parse_args()
- providers: list[type[CodeNodeProvider]] = [Python3CodeProvider, JavascriptCodeProvider]
- code_provider: type[CodeNodeProvider] | None = next(
- (p for p in providers if p.is_accept_language(args["language"])), None
+ code_template = (
+ Python3CodeProvider.get_default_code()
+ if args["language"] == "python"
+ else (JavascriptCodeProvider.get_default_code())
+ if args["language"] == "javascript"
+ else ""
)
- code_template = code_provider.get_default_code() if code_provider else ""
try:
# Generate from nothing for a workflow node
if (args["current"] == code_template or args["current"] == "") and args["node_id"] != "":
diff --git a/api/core/llm_generator/prompts.py b/api/core/llm_generator/prompts.py
index e38828578a9..92683475268 100644
--- a/api/core/llm_generator/prompts.py
+++ b/api/core/llm_generator/prompts.py
@@ -414,7 +414,7 @@ When you are modifying the code, you should remember:
- Get inputs from the parameters of the function and have explicit type annotations.
- Write proper imports at the top of the code.
- Use return statement to return the result.
-- You should return a `dict`.
+- You should return a `dict`. If you need to return a `result: str`, you should `return {"result": result}`.
Your output must strictly follow the schema format, do not output any content outside of the JSON body.
""" # noqa: E501
diff --git a/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx b/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx
index e0e87aa0902..b581da979f3 100644
--- a/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx
+++ b/web/app/components/app/configuration/config/code-generator/get-code-generator-res.tsx
@@ -142,7 +142,7 @@ export const GetCodeGeneratorResModal: FC<IGetCodeGeneratorResProps> = (
ideal_output: ideaOutput,
language: languageMap[codeLanguages] || 'javascript',
})
- if(!currentCode)
+ if((res as any).code) // not current or current is the same as the template would return a code field
res.modified = (res as any).code
if (error) {