app_invoke_entities.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. from enum import Enum
  2. from typing import Any, Optional
  3. from pydantic import BaseModel
  4. from core.app.app_config.entities import AppConfig, EasyUIBasedAppConfig, WorkflowUIBasedAppConfig
  5. from core.entities.provider_configuration import ProviderModelBundle
  6. from core.file.file_obj import FileVar
  7. from core.model_runtime.entities.model_entities import AIModelEntity
  8. class InvokeFrom(Enum):
  9. """
  10. Invoke From.
  11. """
  12. SERVICE_API = 'service-api'
  13. WEB_APP = 'web-app'
  14. EXPLORE = 'explore'
  15. DEBUGGER = 'debugger'
  16. @classmethod
  17. def value_of(cls, value: str) -> 'InvokeFrom':
  18. """
  19. Get value of given mode.
  20. :param value: mode value
  21. :return: mode
  22. """
  23. for mode in cls:
  24. if mode.value == value:
  25. return mode
  26. raise ValueError(f'invalid invoke from value {value}')
  27. def to_source(self) -> str:
  28. """
  29. Get source of invoke from.
  30. :return: source
  31. """
  32. if self == InvokeFrom.WEB_APP:
  33. return 'web_app'
  34. elif self == InvokeFrom.DEBUGGER:
  35. return 'dev'
  36. elif self == InvokeFrom.EXPLORE:
  37. return 'explore_app'
  38. elif self == InvokeFrom.SERVICE_API:
  39. return 'api'
  40. return 'dev'
  41. class ModelConfigWithCredentialsEntity(BaseModel):
  42. """
  43. Model Config With Credentials Entity.
  44. """
  45. provider: str
  46. model: str
  47. model_schema: AIModelEntity
  48. mode: str
  49. provider_model_bundle: ProviderModelBundle
  50. credentials: dict[str, Any] = {}
  51. parameters: dict[str, Any] = {}
  52. stop: list[str] = []
  53. class AppGenerateEntity(BaseModel):
  54. """
  55. App Generate Entity.
  56. """
  57. task_id: str
  58. # app config
  59. app_config: AppConfig
  60. inputs: dict[str, str]
  61. files: list[FileVar] = []
  62. user_id: str
  63. # extras
  64. stream: bool
  65. invoke_from: InvokeFrom
  66. # extra parameters, like: auto_generate_conversation_name
  67. extras: dict[str, Any] = {}
  68. class EasyUIBasedAppGenerateEntity(AppGenerateEntity):
  69. """
  70. Chat Application Generate Entity.
  71. """
  72. # app config
  73. app_config: EasyUIBasedAppConfig
  74. model_config: ModelConfigWithCredentialsEntity
  75. query: Optional[str] = None
  76. class ChatAppGenerateEntity(EasyUIBasedAppGenerateEntity):
  77. """
  78. Chat Application Generate Entity.
  79. """
  80. conversation_id: Optional[str] = None
  81. class CompletionAppGenerateEntity(EasyUIBasedAppGenerateEntity):
  82. """
  83. Completion Application Generate Entity.
  84. """
  85. pass
  86. class AgentChatAppGenerateEntity(EasyUIBasedAppGenerateEntity):
  87. """
  88. Agent Chat Application Generate Entity.
  89. """
  90. conversation_id: Optional[str] = None
  91. class AdvancedChatAppGenerateEntity(AppGenerateEntity):
  92. """
  93. Advanced Chat Application Generate Entity.
  94. """
  95. # app config
  96. app_config: WorkflowUIBasedAppConfig
  97. conversation_id: Optional[str] = None
  98. query: Optional[str] = None
  99. class WorkflowAppGenerateEntity(AppGenerateEntity):
  100. """
  101. Workflow Application Generate Entity.
  102. """
  103. # app config
  104. app_config: WorkflowUIBasedAppConfig