__init__.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. from typing import Optional
  2. from pydantic import Field, NonNegativeInt
  3. from pydantic_settings import BaseSettings
  4. class HostedOpenAiConfig(BaseSettings):
  5. """
  6. Configuration for hosted OpenAI service
  7. """
  8. HOSTED_OPENAI_API_KEY: Optional[str] = Field(
  9. description="API key for hosted OpenAI service",
  10. default=None,
  11. )
  12. HOSTED_OPENAI_API_BASE: Optional[str] = Field(
  13. description="Base URL for hosted OpenAI API",
  14. default=None,
  15. )
  16. HOSTED_OPENAI_API_ORGANIZATION: Optional[str] = Field(
  17. description="Organization ID for hosted OpenAI service",
  18. default=None,
  19. )
  20. HOSTED_OPENAI_TRIAL_ENABLED: bool = Field(
  21. description="Enable trial access to hosted OpenAI service",
  22. default=False,
  23. )
  24. HOSTED_OPENAI_TRIAL_MODELS: str = Field(
  25. description="Comma-separated list of available models for trial access",
  26. default="gpt-3.5-turbo,"
  27. "gpt-3.5-turbo-1106,"
  28. "gpt-3.5-turbo-instruct,"
  29. "gpt-3.5-turbo-16k,"
  30. "gpt-3.5-turbo-16k-0613,"
  31. "gpt-3.5-turbo-0613,"
  32. "gpt-3.5-turbo-0125,"
  33. "text-davinci-003",
  34. )
  35. HOSTED_OPENAI_QUOTA_LIMIT: NonNegativeInt = Field(
  36. description="Quota limit for hosted OpenAI service usage",
  37. default=200,
  38. )
  39. HOSTED_OPENAI_PAID_ENABLED: bool = Field(
  40. description="Enable paid access to hosted OpenAI service",
  41. default=False,
  42. )
  43. HOSTED_OPENAI_PAID_MODELS: str = Field(
  44. description="Comma-separated list of available models for paid access",
  45. default="gpt-4,"
  46. "gpt-4-turbo-preview,"
  47. "gpt-4-turbo-2024-04-09,"
  48. "gpt-4-1106-preview,"
  49. "gpt-4-0125-preview,"
  50. "gpt-3.5-turbo,"
  51. "gpt-3.5-turbo-16k,"
  52. "gpt-3.5-turbo-16k-0613,"
  53. "gpt-3.5-turbo-1106,"
  54. "gpt-3.5-turbo-0613,"
  55. "gpt-3.5-turbo-0125,"
  56. "gpt-3.5-turbo-instruct,"
  57. "text-davinci-003",
  58. )
  59. class HostedAzureOpenAiConfig(BaseSettings):
  60. """
  61. Configuration for hosted Azure OpenAI service
  62. """
  63. HOSTED_AZURE_OPENAI_ENABLED: bool = Field(
  64. description="Enable hosted Azure OpenAI service",
  65. default=False,
  66. )
  67. HOSTED_AZURE_OPENAI_API_KEY: Optional[str] = Field(
  68. description="API key for hosted Azure OpenAI service",
  69. default=None,
  70. )
  71. HOSTED_AZURE_OPENAI_API_BASE: Optional[str] = Field(
  72. description="Base URL for hosted Azure OpenAI API",
  73. default=None,
  74. )
  75. HOSTED_AZURE_OPENAI_QUOTA_LIMIT: NonNegativeInt = Field(
  76. description="Quota limit for hosted Azure OpenAI service usage",
  77. default=200,
  78. )
  79. class HostedAnthropicConfig(BaseSettings):
  80. """
  81. Configuration for hosted Anthropic service
  82. """
  83. HOSTED_ANTHROPIC_API_BASE: Optional[str] = Field(
  84. description="Base URL for hosted Anthropic API",
  85. default=None,
  86. )
  87. HOSTED_ANTHROPIC_API_KEY: Optional[str] = Field(
  88. description="API key for hosted Anthropic service",
  89. default=None,
  90. )
  91. HOSTED_ANTHROPIC_TRIAL_ENABLED: bool = Field(
  92. description="Enable trial access to hosted Anthropic service",
  93. default=False,
  94. )
  95. HOSTED_ANTHROPIC_QUOTA_LIMIT: NonNegativeInt = Field(
  96. description="Quota limit for hosted Anthropic service usage",
  97. default=600000,
  98. )
  99. HOSTED_ANTHROPIC_PAID_ENABLED: bool = Field(
  100. description="Enable paid access to hosted Anthropic service",
  101. default=False,
  102. )
  103. class HostedMinmaxConfig(BaseSettings):
  104. """
  105. Configuration for hosted Minmax service
  106. """
  107. HOSTED_MINIMAX_ENABLED: bool = Field(
  108. description="Enable hosted Minmax service",
  109. default=False,
  110. )
  111. class HostedSparkConfig(BaseSettings):
  112. """
  113. Configuration for hosted Spark service
  114. """
  115. HOSTED_SPARK_ENABLED: bool = Field(
  116. description="Enable hosted Spark service",
  117. default=False,
  118. )
  119. class HostedZhipuAIConfig(BaseSettings):
  120. """
  121. Configuration for hosted ZhipuAI service
  122. """
  123. HOSTED_ZHIPUAI_ENABLED: bool = Field(
  124. description="Enable hosted ZhipuAI service",
  125. default=False,
  126. )
  127. class HostedModerationConfig(BaseSettings):
  128. """
  129. Configuration for hosted Moderation service
  130. """
  131. HOSTED_MODERATION_ENABLED: bool = Field(
  132. description="Enable hosted Moderation service",
  133. default=False,
  134. )
  135. HOSTED_MODERATION_PROVIDERS: str = Field(
  136. description="Comma-separated list of moderation providers",
  137. default="",
  138. )
  139. class HostedFetchAppTemplateConfig(BaseSettings):
  140. """
  141. Configuration for fetching app templates
  142. """
  143. HOSTED_FETCH_APP_TEMPLATES_MODE: str = Field(
  144. description="Mode for fetching app templates: remote, db, or builtin" " default to remote,",
  145. default="remote",
  146. )
  147. HOSTED_FETCH_APP_TEMPLATES_REMOTE_DOMAIN: str = Field(
  148. description="Domain for fetching remote app templates",
  149. default="https://tmpl.dify.ai",
  150. )
  151. class HostedServiceConfig(
  152. # place the configs in alphabet order
  153. HostedAnthropicConfig,
  154. HostedAzureOpenAiConfig,
  155. HostedFetchAppTemplateConfig,
  156. HostedMinmaxConfig,
  157. HostedOpenAiConfig,
  158. HostedSparkConfig,
  159. HostedZhipuAIConfig,
  160. # moderation
  161. HostedModerationConfig,
  162. ):
  163. pass