app.ts 5.7 KB

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