app.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. export enum ProviderType {
  2. openai = 'openai',
  3. anthropic = 'anthropic',
  4. azure_openai = 'azure_openai',
  5. replicate = 'replicate',
  6. huggingface_hub = 'huggingface_hub',
  7. minimax = 'minimax',
  8. tongyi = 'tongyi',
  9. spark = 'spark',
  10. }
  11. export enum AppType {
  12. 'chat' = 'chat',
  13. 'completion' = 'completion',
  14. }
  15. export type VariableInput = {
  16. key: string
  17. name: string
  18. value: string
  19. }
  20. /**
  21. * App modes
  22. */
  23. export const AppModes = ['completion', 'chat'] as const
  24. export type AppMode = typeof AppModes[number]
  25. /**
  26. * Variable type
  27. */
  28. export const VariableTypes = ['string', 'number', 'select'] as const
  29. export type VariableType = typeof VariableTypes[number]
  30. /**
  31. * Prompt variable parameter
  32. */
  33. export type PromptVariable = {
  34. /** Variable key */
  35. key: string
  36. /** Variable name */
  37. name: string
  38. /** Type */
  39. type: VariableType
  40. required: boolean
  41. /** Enumeration of single-selection drop-down values */
  42. options?: string[]
  43. max_length?: number
  44. }
  45. export type TextTypeFormItem = {
  46. label: string
  47. variable: string
  48. required: boolean
  49. max_length: number
  50. }
  51. export type SelectTypeFormItem = {
  52. label: string
  53. variable: string
  54. required: boolean
  55. options: string[]
  56. }
  57. /**
  58. * User Input Form Item
  59. */
  60. export type UserInputFormItem = {
  61. 'text-input': TextTypeFormItem
  62. } | {
  63. 'select': SelectTypeFormItem
  64. }
  65. export type ToolItem = {
  66. dataset: {
  67. enabled: boolean
  68. id: string
  69. }
  70. } | {
  71. 'sensitive-word-avoidance': {
  72. enabled: boolean
  73. words: string[]
  74. canned_response: string
  75. }
  76. }
  77. /**
  78. * Model configuration. The backend type.
  79. */
  80. export type ModelConfig = {
  81. opening_statement: string
  82. pre_prompt: string
  83. user_input_form: UserInputFormItem[]
  84. dataset_query_variable?: string
  85. more_like_this: {
  86. enabled: boolean
  87. }
  88. suggested_questions_after_answer: {
  89. enabled: boolean
  90. }
  91. speech_to_text: {
  92. enabled: boolean
  93. }
  94. retriever_resource: {
  95. enabled: boolean
  96. }
  97. agent_mode: {
  98. enabled: boolean
  99. tools: ToolItem[]
  100. }
  101. model: {
  102. /** LLM provider, e.g., OPENAI */
  103. provider: string
  104. /** Model name, e.g, gpt-3.5.turbo */
  105. name: string
  106. /** Default Completion call parameters */
  107. completion_params: {
  108. /** Maximum number of tokens in the answer message returned by Completion */
  109. max_tokens: number
  110. /**
  111. * A number between 0 and 2.
  112. * The larger the number, the more random the result;
  113. * otherwise, the more deterministic.
  114. * When in use, choose either `temperature` or `top_p`.
  115. * Default is 1.
  116. */
  117. temperature: number
  118. /**
  119. * Represents the proportion of probability mass samples to take,
  120. * e.g., 0.1 means taking the top 10% probability mass samples.
  121. * The determinism between the samples is basically consistent.
  122. * Among these results, the `top_p` probability mass results are taken.
  123. * When in use, choose either `temperature` or `top_p`.
  124. * Default is 1.
  125. */
  126. top_p: number
  127. /** When enabled, the Completion Text will concatenate the Prompt content together and return it. */
  128. echo: boolean
  129. /**
  130. * Specify up to 4 to automatically stop generating before the text specified in `stop`.
  131. * Suitable for use in chat mode.
  132. * For example, specify "Q" and "A",
  133. * and provide some Q&A examples as context,
  134. * and the model will give out in Q&A format and stop generating before Q&A.
  135. */
  136. stop: string[]
  137. /**
  138. * A number between -2.0 and 2.0.
  139. * The larger the value, the less the model will repeat topics and the more it will provide new topics.
  140. */
  141. presence_penalty: number
  142. /**
  143. * A number between -2.0 and 2.0.
  144. * A lower setting will make the model appear less cultured,
  145. * always repeating expressions.
  146. * The difference between `frequency_penalty` and `presence_penalty`
  147. * is that `frequency_penalty` penalizes a word based on its frequency in the training data,
  148. * while `presence_penalty` penalizes a word based on its occurrence in the input text.
  149. */
  150. frequency_penalty: number
  151. }
  152. }
  153. }
  154. export const LanguagesSupported = ['zh-Hans', 'en-US'] as const
  155. export type Language = typeof LanguagesSupported[number]
  156. /**
  157. * Web Application Configuration
  158. */
  159. export type SiteConfig = {
  160. /** Application URL Identifier: `http://dify.app/{access_token}` */
  161. access_token: string
  162. /** Public Title */
  163. title: string
  164. /** Application Description will be shown in the Client */
  165. description: string
  166. /** Author */
  167. author: string
  168. /** User Support Email Address */
  169. support_email: string
  170. /**
  171. * Default Language, e.g. zh-Hans, en-US
  172. * Use standard RFC 4646, see https://www.ruanyifeng.com/blog/2008/02/codes_for_language_names.html
  173. */
  174. default_language: Language
  175. /** Custom Domain */
  176. customize_domain: string
  177. /** Theme */
  178. theme: string
  179. /** Custom Token strategy Whether Terminal Users can choose their OpenAI Key */
  180. customize_token_strategy: 'must' | 'allow' | 'not_allow'
  181. /** Is Prompt Public */
  182. prompt_public: boolean
  183. /** Web API and APP Base Domain Name */
  184. app_base_url: string
  185. /** Copyright */
  186. copyright: string
  187. /** Privacy Policy */
  188. privacy_policy: string
  189. icon: string
  190. icon_background: string
  191. }
  192. /**
  193. * App
  194. */
  195. export type App = {
  196. /** App ID */
  197. id: string
  198. /** Name */
  199. name: string
  200. /** Icon */
  201. icon: string
  202. /** Icon Background */
  203. icon_background: string
  204. /** Mode */
  205. mode: AppMode
  206. /** Enable web app */
  207. enable_site: boolean
  208. /** Enable web API */
  209. enable_api: boolean
  210. /** API requests per minute, default is 60 */
  211. api_rpm: number
  212. /** API requests per hour, default is 3600 */
  213. api_rph: number
  214. /** Whether it's a demo app */
  215. is_demo: boolean
  216. /** Model configuration */
  217. model_config: ModelConfig
  218. app_model_config: ModelConfig
  219. /** Timestamp of creation */
  220. created_at: number
  221. /** Web Application Configuration */
  222. site: SiteConfig
  223. /** api site url */
  224. api_base_url: string
  225. }
  226. /**
  227. * App Template
  228. */
  229. export type AppTemplate = {
  230. /** Name */
  231. name: string
  232. /** Description */
  233. description: string
  234. /** Mode */
  235. mode: AppMode
  236. /** Model */
  237. model_config: ModelConfig
  238. }