mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 17:38:04 +08:00
chore: auto-dify init commit
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import os
|
||||
from typing import cast
|
||||
|
||||
from flask_login import current_user # type: ignore
|
||||
from flask_restful import Resource, reqparse # type: ignore
|
||||
@ -11,8 +12,11 @@ from controllers.console.app.error import (
|
||||
ProviderQuotaExceededError,
|
||||
)
|
||||
from controllers.console.wraps import account_initialization_required, setup_required
|
||||
from core.auto.workflow_generator.workflow_generator import WorkflowGenerator
|
||||
from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError
|
||||
from core.llm_generator.llm_generator import LLMGenerator
|
||||
from core.model_manager import ModelManager
|
||||
from core.model_runtime.entities.model_entities import ModelType
|
||||
from core.model_runtime.errors.invoke import InvokeError
|
||||
from libs.login import login_required
|
||||
|
||||
@ -85,5 +89,45 @@ class RuleCodeGenerateApi(Resource):
|
||||
return code_result
|
||||
|
||||
|
||||
class AutoGenerateWorkflowApi(Resource):
|
||||
@setup_required
|
||||
@login_required
|
||||
@account_initialization_required
|
||||
def post(self):
|
||||
"""
|
||||
Auto generate workflow
|
||||
"""
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument("instruction", type=str, required=True, location="json")
|
||||
parser.add_argument("model_config", type=dict, required=True, location="json")
|
||||
tenant_id = cast(str, current_user.current_tenant_id)
|
||||
args = parser.parse_args()
|
||||
instruction = args.get("instruction")
|
||||
if not instruction:
|
||||
raise ValueError("Instruction is required")
|
||||
if not args.get("model_config"):
|
||||
raise ValueError("Model config is required")
|
||||
model_config = cast(dict, args.get("model_config"))
|
||||
model_manager = ModelManager()
|
||||
model_instance = model_manager.get_model_instance(
|
||||
tenant_id=tenant_id,
|
||||
model_type=ModelType.LLM,
|
||||
provider=model_config.get("provider", ""),
|
||||
model=model_config.get("name", ""),
|
||||
)
|
||||
workflow_generator = WorkflowGenerator(
|
||||
model_instance=model_instance,
|
||||
)
|
||||
workflow_yaml = workflow_generator.generate_workflow(
|
||||
user_requirement=instruction,
|
||||
)
|
||||
return workflow_yaml
|
||||
|
||||
|
||||
api.add_resource(RuleGenerateApi, "/rule-generate")
|
||||
api.add_resource(RuleCodeGenerateApi, "/rule-code-generate")
|
||||
api.add_resource(
|
||||
AutoGenerateWorkflowApi,
|
||||
"/auto-generate",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user