dify/api/controllers/web/app.py

47 lines
1.5 KiB
Python
Raw Normal View History

from flask_restful import marshal_with
from controllers.common import fields
from controllers.common import helpers as controller_helpers
2023-05-15 08:51:32 +08:00
from controllers.web import api
from controllers.web.error import AppUnavailableError
2023-05-15 08:51:32 +08:00
from controllers.web.wraps import WebApiResource
2024-05-15 16:14:49 +08:00
from models.model import App, AppMode
from services.app_service import AppService
2023-05-15 08:51:32 +08:00
class AppParameterApi(WebApiResource):
"""Resource for app variables."""
@marshal_with(fields.parameters_fields)
def get(self, app_model: App, end_user):
2023-05-15 08:51:32 +08:00
"""Retrieve app parameters."""
if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:
workflow = app_model.workflow
if workflow is None:
raise AppUnavailableError()
features_dict = workflow.features_dict
user_input_form = workflow.user_input_form(to_old_structure=True)
else:
app_model_config = app_model.app_model_config
if app_model_config is None:
raise AppUnavailableError()
features_dict = app_model_config.to_dict()
user_input_form = features_dict.get("user_input_form", [])
2023-05-15 08:51:32 +08:00
return controller_helpers.get_parameters_from_feature_dict(
features_dict=features_dict, user_input_form=user_input_form
)
2023-05-15 08:51:32 +08:00
class AppMeta(WebApiResource):
def get(self, app_model: App, end_user):
"""Get app meta"""
return AppService().get_app_meta(app_model)
2023-05-15 08:51:32 +08:00
api.add_resource(AppParameterApi, "/parameters")
api.add_resource(AppMeta, "/meta")