app.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. more_like_this: {
  85. enabled: boolean
  86. }
  87. suggested_questions_after_answer: {
  88. enabled: boolean
  89. }
  90. speech_to_text: {
  91. enabled: boolean
  92. }
  93. agent_mode: {
  94. enabled: boolean
  95. tools: ToolItem[]
  96. }
  97. model: {
  98. /** LLM provider, e.g., OPENAI */
  99. provider: string
  100. /** Model name, e.g, gpt-3.5.turbo */
  101. name: string
  102. /** Default Completion call parameters */
  103. completion_params: {
  104. /** Maximum number of tokens in the answer message returned by Completion */
  105. max_tokens: number
  106. /**
  107. * A number between 0 and 2.
  108. * The larger the number, the more random the result;
  109. * otherwise, the more deterministic.
  110. * When in use, choose either `temperature` or `top_p`.
  111. * Default is 1.
  112. */
  113. temperature: number
  114. /**
  115. * Represents the proportion of probability mass samples to take,
  116. * e.g., 0.1 means taking the top 10% probability mass samples.
  117. * The determinism between the samples is basically consistent.
  118. * Among these results, the `top_p` probability mass results are taken.
  119. * When in use, choose either `temperature` or `top_p`.
  120. * Default is 1.
  121. */
  122. top_p: number
  123. /** When enabled, the Completion Text will concatenate the Prompt content together and return it. */
  124. echo: boolean
  125. /**
  126. * Specify up to 4 to automatically stop generating before the text specified in `stop`.
  127. * Suitable for use in chat mode.
  128. * For example, specify "Q" and "A",
  129. * and provide some Q&A examples as context,
  130. * and the model will give out in Q&A format and stop generating before Q&A.
  131. */
  132. stop: string[]
  133. /**
  134. * A number between -2.0 and 2.0.
  135. * The larger the value, the less the model will repeat topics and the more it will provide new topics.
  136. */
  137. presence_penalty: number
  138. /**
  139. * A number between -2.0 and 2.0.
  140. * A lower setting will make the model appear less cultured,
  141. * always repeating expressions.
  142. * The difference between `frequency_penalty` and `presence_penalty`
  143. * is that `frequency_penalty` penalizes a word based on its frequency in the training data,
  144. * while `presence_penalty` penalizes a word based on its occurrence in the input text.
  145. */
  146. frequency_penalty: number
  147. }
  148. }
  149. }
  150. export const LanguagesSupported = ['zh-Hans', 'en-US'] as const
  151. export type Language = typeof LanguagesSupported[number]
  152. /**
  153. * Web Application Configuration
  154. */
  155. export type SiteConfig = {
  156. /** Application URL Identifier: `http://dify.app/{access_token}` */
  157. access_token: string
  158. /** Public Title */
  159. title: string
  160. /** Application Description will be shown in the Client */
  161. description: string
  162. /** Author */
  163. author: string
  164. /** User Support Email Address */
  165. support_email: string
  166. /**
  167. * Default Language, e.g. zh-Hans, en-US
  168. * Use standard RFC 4646, see https://www.ruanyifeng.com/blog/2008/02/codes_for_language_names.html
  169. */
  170. default_language: Language
  171. /** Custom Domain */
  172. customize_domain: string
  173. /** Theme */
  174. theme: string
  175. /** Custom Token strategy Whether Terminal Users can choose their OpenAI Key */
  176. customize_token_strategy: 'must' | 'allow' | 'not_allow'
  177. /** Is Prompt Public */
  178. prompt_public: boolean
  179. /** Web API and APP Base Domain Name */
  180. app_base_url: string
  181. /** Copyright */
  182. copyright: string
  183. /** Privacy Policy */
  184. privacy_policy: string
  185. icon: string
  186. icon_background: string
  187. }
  188. /**
  189. * App
  190. */
  191. export type App = {
  192. /** App ID */
  193. id: string
  194. /** Name */
  195. name: string
  196. /** Icon */
  197. icon: string
  198. /** Icon Background */
  199. icon_background: string
  200. /** Mode */
  201. mode: AppMode
  202. /** Enable web app */
  203. enable_site: boolean
  204. /** Enable web API */
  205. enable_api: boolean
  206. /** API requests per minute, default is 60 */
  207. api_rpm: number
  208. /** API requests per hour, default is 3600 */
  209. api_rph: number
  210. /** Whether it's a demo app */
  211. is_demo: boolean
  212. /** Model configuration */
  213. model_config: ModelConfig
  214. app_model_config: ModelConfig
  215. /** Timestamp of creation */
  216. created_at: number
  217. /** Web Application Configuration */
  218. site: SiteConfig
  219. /** api site url */
  220. api_base_url: string
  221. }
  222. /**
  223. * App Template
  224. */
  225. export type AppTemplate = {
  226. /** Name */
  227. name: string
  228. /** Description */
  229. description: string
  230. /** Mode */
  231. mode: AppMode
  232. /** Model */
  233. model_config: ModelConfig
  234. }