app.ts 5.8 KB

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