app.ts 5.8 KB

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