__init__.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. from typing import Optional
  2. from pydantic import AliasChoices, BaseModel, Field, NonNegativeInt, PositiveInt
  3. class SecurityConfigs(BaseModel):
  4. """
  5. Secret Key configs
  6. """
  7. SECRET_KEY: Optional[str] = Field(
  8. description='Your App secret key will be used for securely signing the session cookie'
  9. 'Make sure you are changing this key for your deployment with a strong key.'
  10. 'You can generate a strong key using `openssl rand -base64 42`.'
  11. 'Alternatively you can set it with `SECRET_KEY` environment variable.',
  12. default=None,
  13. )
  14. class AppExecutionConfigs(BaseModel):
  15. """
  16. App Execution configs
  17. """
  18. APP_MAX_EXECUTION_TIME: PositiveInt = Field(
  19. description='execution timeout in seconds for app execution',
  20. default=1200,
  21. )
  22. class CodeExecutionSandboxConfigs(BaseModel):
  23. """
  24. Code Execution Sandbox configs
  25. """
  26. CODE_EXECUTION_ENDPOINT: str = Field(
  27. description='whether to enable HTTP response compression of gzip',
  28. default='http://sandbox:8194',
  29. )
  30. CODE_EXECUTION_API_KEY: str = Field(
  31. description='API key for code execution service',
  32. default='dify-sandbox',
  33. )
  34. class EndpointConfigs(BaseModel):
  35. """
  36. Module URL configs
  37. """
  38. CONSOLE_API_URL: str = Field(
  39. description='The backend URL prefix of the console API.'
  40. 'used to concatenate the login authorization callback or notion integration callback.',
  41. default='https://cloud.dify.ai',
  42. )
  43. CONSOLE_WEB_URL: str = Field(
  44. description='The front-end URL prefix of the console web.'
  45. 'used to concatenate some front-end addresses and for CORS configuration use.',
  46. default='https://cloud.dify.ai',
  47. )
  48. SERVICE_API_URL: str = Field(
  49. description='Service API Url prefix.'
  50. 'used to display Service API Base Url to the front-end.',
  51. default='https://api.dify.ai',
  52. )
  53. APP_WEB_URL: str = Field(
  54. description='WebApp Url prefix.'
  55. 'used to display WebAPP API Base Url to the front-end.',
  56. default='https://udify.app',
  57. )
  58. class FileAccessConfigs(BaseModel):
  59. """
  60. File Access configs
  61. """
  62. FILES_URL: str = Field(
  63. description='File preview or download Url prefix.'
  64. ' used to display File preview or download Url to the front-end or as Multi-model inputs;'
  65. 'Url is signed and has expiration time.',
  66. validation_alias=AliasChoices('FILES_URL', 'CONSOLE_API_URL'),
  67. alias_priority=1,
  68. default='https://cloud.dify.ai',
  69. )
  70. FILES_ACCESS_TIMEOUT: int = Field(
  71. description='timeout in seconds for file accessing',
  72. default=300,
  73. )
  74. class FileUploadConfigs(BaseModel):
  75. """
  76. File Uploading configs
  77. """
  78. UPLOAD_FILE_SIZE_LIMIT: NonNegativeInt = Field(
  79. description='size limit in Megabytes for uploading files',
  80. default=15,
  81. )
  82. UPLOAD_FILE_BATCH_LIMIT: NonNegativeInt = Field(
  83. description='batch size limit for uploading files',
  84. default=5,
  85. )
  86. UPLOAD_IMAGE_FILE_SIZE_LIMIT: NonNegativeInt = Field(
  87. description='image file size limit in Megabytes for uploading files',
  88. default=10,
  89. )
  90. BATCH_UPLOAD_LIMIT: NonNegativeInt = Field(
  91. description='', # todo: to be clarified
  92. default=20,
  93. )
  94. class HttpConfigs(BaseModel):
  95. """
  96. HTTP configs
  97. """
  98. API_COMPRESSION_ENABLED: bool = Field(
  99. description='whether to enable HTTP response compression of gzip',
  100. default=False,
  101. )
  102. class InnerAPIConfigs(BaseModel):
  103. """
  104. Inner API configs
  105. """
  106. INNER_API: bool = Field(
  107. description='whether to enable the inner API',
  108. default=False,
  109. )
  110. INNER_API_KEY: Optional[str] = Field(
  111. description='The inner API key is used to authenticate the inner API',
  112. default=None,
  113. )
  114. class LoggingConfigs(BaseModel):
  115. """
  116. Logging configs
  117. """
  118. LOG_LEVEL: str = Field(
  119. description='Log output level, default to INFO.'
  120. 'It is recommended to set it to ERROR for production.',
  121. default='INFO',
  122. )
  123. LOG_FILE: Optional[str] = Field(
  124. description='logging output file path',
  125. default=None,
  126. )
  127. LOG_FORMAT: str = Field(
  128. description='log format',
  129. default='%(asctime)s.%(msecs)03d %(levelname)s [%(threadName)s] [%(filename)s:%(lineno)d] - %(message)s',
  130. )
  131. LOG_DATEFORMAT: Optional[str] = Field(
  132. description='log date format',
  133. default=None,
  134. )
  135. class ModelLoadBalanceConfigs(BaseModel):
  136. """
  137. Model load balance configs
  138. """
  139. MODEL_LB_ENABLED: bool = Field(
  140. description='whether to enable model load balancing',
  141. default=False,
  142. )
  143. class BillingConfigs(BaseModel):
  144. """
  145. Platform Billing Configurations
  146. """
  147. BILLING_ENABLED: bool = Field(
  148. description='whether to enable billing',
  149. default=False,
  150. )
  151. class UpdateConfigs(BaseModel):
  152. """
  153. Update configs
  154. """
  155. CHECK_UPDATE_URL: str = Field(
  156. description='url for checking updates',
  157. default='https://updates.dify.ai',
  158. )
  159. class WorkflowConfigs(BaseModel):
  160. """
  161. Workflow feature configs
  162. """
  163. WORKFLOW_MAX_EXECUTION_STEPS: PositiveInt = Field(
  164. description='max execution steps in single workflow execution',
  165. default=500,
  166. )
  167. WORKFLOW_MAX_EXECUTION_TIME: PositiveInt = Field(
  168. description='max execution time in seconds in single workflow execution',
  169. default=1200,
  170. )
  171. WORKFLOW_CALL_MAX_DEPTH: PositiveInt = Field(
  172. description='max depth of calling in single workflow execution',
  173. default=5,
  174. )
  175. class OAuthConfigs(BaseModel):
  176. """
  177. oauth configs
  178. """
  179. OAUTH_REDIRECT_PATH: str = Field(
  180. description='redirect path for OAuth',
  181. default='/console/api/oauth/authorize',
  182. )
  183. GITHUB_CLIENT_ID: Optional[str] = Field(
  184. description='GitHub client id for OAuth',
  185. default=None,
  186. )
  187. GITHUB_CLIENT_SECRET: Optional[str] = Field(
  188. description='GitHub client secret key for OAuth',
  189. default=None,
  190. )
  191. GOOGLE_CLIENT_ID: Optional[str] = Field(
  192. description='Google client id for OAuth',
  193. default=None,
  194. )
  195. GOOGLE_CLIENT_SECRET: Optional[str] = Field(
  196. description='Google client secret key for OAuth',
  197. default=None,
  198. )
  199. class ModerationConfigs(BaseModel):
  200. """
  201. Moderation in app configs.
  202. """
  203. # todo: to be clarified in usage and unit
  204. OUTPUT_MODERATION_BUFFER_SIZE: PositiveInt = Field(
  205. description='buffer size for moderation',
  206. default=300,
  207. )
  208. class ToolConfigs(BaseModel):
  209. """
  210. Tool configs
  211. """
  212. TOOL_ICON_CACHE_MAX_AGE: PositiveInt = Field(
  213. description='max age in seconds for tool icon caching',
  214. default=3600,
  215. )
  216. class MailConfigs(BaseModel):
  217. """
  218. Mail Configurations
  219. """
  220. MAIL_TYPE: Optional[str] = Field(
  221. description='Mail provider type name, default to None, availabile values are `smtp` and `resend`.',
  222. default=None,
  223. )
  224. MAIL_DEFAULT_SEND_FROM: Optional[str] = Field(
  225. description='default email address for sending from ',
  226. default=None,
  227. )
  228. RESEND_API_KEY: Optional[str] = Field(
  229. description='API key for Resend',
  230. default=None,
  231. )
  232. RESEND_API_URL: Optional[str] = Field(
  233. description='API URL for Resend',
  234. default=None,
  235. )
  236. SMTP_SERVER: Optional[str] = Field(
  237. description='smtp server host',
  238. default=None,
  239. )
  240. SMTP_PORT: Optional[int] = Field(
  241. description='smtp server port',
  242. default=None,
  243. )
  244. SMTP_USERNAME: Optional[str] = Field(
  245. description='smtp server username',
  246. default=None,
  247. )
  248. SMTP_PASSWORD: Optional[str] = Field(
  249. description='smtp server password',
  250. default=None,
  251. )
  252. SMTP_USE_TLS: bool = Field(
  253. description='whether to use TLS connection to smtp server',
  254. default=False,
  255. )
  256. SMTP_OPPORTUNISTIC_TLS: bool = Field(
  257. description='whether to use opportunistic TLS connection to smtp server',
  258. default=False,
  259. )
  260. class RagEtlConfigs(BaseModel):
  261. """
  262. RAG ETL Configurations.
  263. """
  264. ETL_TYPE: str = Field(
  265. description='RAG ETL type name, default to `dify`, available values are `dify` and `Unstructured`. ',
  266. default='dify',
  267. )
  268. KEYWORD_DATA_SOURCE_TYPE: str = Field(
  269. description='source type for keyword data, default to `database`, available values are `database` .',
  270. default='database',
  271. )
  272. UNSTRUCTURED_API_URL: Optional[str] = Field(
  273. description='API URL for Unstructured',
  274. default=None,
  275. )
  276. UNSTRUCTURED_API_KEY: Optional[str] = Field(
  277. description='API key for Unstructured',
  278. default=None,
  279. )
  280. class DataSetConfigs(BaseModel):
  281. """
  282. Dataset configs
  283. """
  284. CLEAN_DAY_SETTING: PositiveInt = Field(
  285. description='interval in days for cleaning up dataset',
  286. default=30,
  287. )
  288. class WorkspaceConfigs(BaseModel):
  289. """
  290. Workspace configs
  291. """
  292. INVITE_EXPIRY_HOURS: PositiveInt = Field(
  293. description='workspaces invitation expiration in hours',
  294. default=72,
  295. )
  296. class IndexingConfigs(BaseModel):
  297. """
  298. Indexing configs.
  299. """
  300. INDEXING_MAX_SEGMENTATION_TOKENS_LENGTH: PositiveInt = Field(
  301. description='max segmentation token length for indexing',
  302. default=1000,
  303. )
  304. class ImageFormatConfigs(BaseModel):
  305. MULTIMODAL_SEND_IMAGE_FORMAT: str = Field(
  306. description='multi model send image format, support base64, url, default is base64',
  307. default='base64',
  308. )
  309. class FeatureConfigs(
  310. # place the configs in alphabet order
  311. AppExecutionConfigs,
  312. BillingConfigs,
  313. CodeExecutionSandboxConfigs,
  314. DataSetConfigs,
  315. EndpointConfigs,
  316. FileAccessConfigs,
  317. FileUploadConfigs,
  318. HttpConfigs,
  319. ImageFormatConfigs,
  320. InnerAPIConfigs,
  321. IndexingConfigs,
  322. LoggingConfigs,
  323. MailConfigs,
  324. ModelLoadBalanceConfigs,
  325. ModerationConfigs,
  326. OAuthConfigs,
  327. RagEtlConfigs,
  328. SecurityConfigs,
  329. ToolConfigs,
  330. UpdateConfigs,
  331. WorkflowConfigs,
  332. WorkspaceConfigs,
  333. ):
  334. pass