From 0ee992733c500d3f11bd26267a8a436e29224335 Mon Sep 17 00:00:00 2001 From: stream Date: Mon, 21 Jul 2025 18:34:50 +0800 Subject: [PATCH] feat: template for instruction generation --- api/controllers/console/app/generator.py | 19 +++++++++++++++++++ api/core/llm_generator/prompts.py | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/api/controllers/console/app/generator.py b/api/controllers/console/app/generator.py index 1902471a0a..0fc8a76c22 100644 --- a/api/controllers/console/app/generator.py +++ b/api/controllers/console/app/generator.py @@ -196,8 +196,27 @@ class InstructionGenerateApi(Resource): except InvokeError as e: raise CompletionRequestError(e.description) +class InstructionGenerationTemplateApi(Resource): + @setup_required + @login_required + @account_initialization_required + def post(self) -> dict: + parser = reqparse.RequestParser() + parser.add_argument("type", type=str, required=True, default=False, location="json") + args = parser.parse_args() + match args["type"]: + case "prompt": + from core.llm_generator.prompts import INSTRUCTION_GENERATE_TEMPLATE_PROMPT + return { "data": INSTRUCTION_GENERATE_TEMPLATE_PROMPT } + case "code": + from core.llm_generator.prompts import INSTRUCTION_GENERATE_TEMPLATE_CODE + return { "data": INSTRUCTION_GENERATE_TEMPLATE_CODE } + case _: + raise ValueError(f"Invalid type: {args['type']}") + api.add_resource(RuleGenerateApi, "/rule-generate") api.add_resource(RuleCodeGenerateApi, "/rule-code-generate") api.add_resource(RuleStructuredOutputGenerateApi, "/rule-structured-output-generate") api.add_resource(InstructionGenerateApi, "/instruction-generate") +api.add_resource(InstructionGenerationTemplateApi, "/instruction-generate/template") diff --git a/api/core/llm_generator/prompts.py b/api/core/llm_generator/prompts.py index f522e805c2..ace8ac73a6 100644 --- a/api/core/llm_generator/prompts.py +++ b/api/core/llm_generator/prompts.py @@ -409,3 +409,11 @@ Both your input and output should be in JSON format. Your output must strictly follow the schema format, do not output any content outside of the JSON body. """ # noqa: E501 + +INSTRUCTION_GENERATE_TEMPLATE_PROMPT = """ +The output of this prompt is not as expected. You should edit the prompt according to the IDEAL OUTPUT. +""" # noqa: E501 + +INSTRUCTION_GENERATE_TEMPLATE_CODE = """ +Please fix the errors in the error message. +""" # noqa: E501