You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from flask_restful import Resource, marshal_with
  2. from controllers.common import fields
  3. from controllers.service_api import api
  4. from controllers.service_api.app.error import AppUnavailableError
  5. from controllers.service_api.wraps import validate_app_token
  6. from core.app.app_config.common.parameters_mapping import get_parameters_from_feature_dict
  7. from models.model import App, AppMode
  8. from services.app_service import AppService
  9. class AppParameterApi(Resource):
  10. """Resource for app variables."""
  11. @validate_app_token
  12. @marshal_with(fields.parameters_fields)
  13. def get(self, app_model: App):
  14. """Retrieve app parameters."""
  15. if app_model.mode in {AppMode.ADVANCED_CHAT.value, AppMode.WORKFLOW.value}:
  16. workflow = app_model.workflow
  17. if workflow is None:
  18. raise AppUnavailableError()
  19. features_dict = workflow.features_dict
  20. user_input_form = workflow.user_input_form(to_old_structure=True)
  21. else:
  22. app_model_config = app_model.app_model_config
  23. if app_model_config is None:
  24. raise AppUnavailableError()
  25. features_dict = app_model_config.to_dict()
  26. user_input_form = features_dict.get("user_input_form", [])
  27. return get_parameters_from_feature_dict(features_dict=features_dict, user_input_form=user_input_form)
  28. class AppMetaApi(Resource):
  29. @validate_app_token
  30. def get(self, app_model: App):
  31. """Get app meta"""
  32. return AppService().get_app_meta(app_model)
  33. class AppInfoApi(Resource):
  34. @validate_app_token
  35. def get(self, app_model: App):
  36. """Get app information"""
  37. tags = [tag.name for tag in app_model.tags]
  38. return {
  39. "name": app_model.name,
  40. "description": app_model.description,
  41. "tags": tags,
  42. "mode": app_model.mode,
  43. "author_name": app_model.author_name,
  44. }
  45. api.add_resource(AppParameterApi, "/parameters")
  46. api.add_resource(AppMetaApi, "/meta")
  47. api.add_resource(AppInfoApi, "/info")