app.ts 6.0 KB

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