app.ts 6.6 KB

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