Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py57 linesDownload Raw Back to app
1from flask_restful import Resource, marshal_with2 3from controllers.common import fields4from controllers.common import helpers as controller_helpers5from controllers.service_api import api6from controllers.service_api.app.error import AppUnavailableError7from controllers.service_api.wraps import validate_app_token8from models.model import App, AppMode9from services.app_service import AppService10 11 12class AppParameterApi(Resource):13    """Resource for app variables."""14 15    @validate_app_token16    @marshal_with(fields.parameters_fields)17    def get(self, app_model: App):18        """Retrieve app parameters."""19        if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:20            workflow = app_model.workflow21            if workflow is None:22                raise AppUnavailableError()23 24            features_dict = workflow.features_dict25            user_input_form = workflow.user_input_form(to_old_structure=True)26        else:27            app_model_config = app_model.app_model_config28            if app_model_config is None:29                raise AppUnavailableError()30 31            features_dict = app_model_config.to_dict()32 33            user_input_form = features_dict.get("user_input_form", [])34 35        return controller_helpers.get_parameters_from_feature_dict(36            features_dict=features_dict, user_input_form=user_input_form37        )38 39 40class AppMetaApi(Resource):41    @validate_app_token42    def get(self, app_model: App):43        """Get app meta"""44        return AppService().get_app_meta(app_model)45 46 47class AppInfoApi(Resource):48    @validate_app_token49    def get(self, app_model: App):50        """Get app information"""51        return {"name": app_model.name, "description": app_model.description}52 53 54api.add_resource(AppParameterApi, "/parameters")55api.add_resource(AppMetaApi, "/meta")56api.add_resource(AppInfoApi, "/info")57