app.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. import type { AnnotationReplyConfig, ChatPromptConfig, CompletionPromptConfig, DatasetConfigs, PromptMode } from '@/models/debug'
  2. import type { CollectionType } from '@/app/components/tools/types'
  3. import type { LanguagesSupported } from '@/i18n/language'
  4. import type { Tag } from '@/app/components/base/tag-management/constant'
  5. import type {
  6. RerankingModeEnum,
  7. WeightedScoreEnum,
  8. } from '@/models/datasets'
  9. import type { UploadFileSetting } from '@/app/components/workflow/types'
  10. export enum Theme {
  11. light = 'light',
  12. dark = 'dark',
  13. }
  14. export enum ProviderType {
  15. openai = 'openai',
  16. anthropic = 'anthropic',
  17. azure_openai = 'azure_openai',
  18. replicate = 'replicate',
  19. huggingface_hub = 'huggingface_hub',
  20. minimax = 'minimax',
  21. tongyi = 'tongyi',
  22. spark = 'spark',
  23. }
  24. export enum AppType {
  25. 'chat' = 'chat',
  26. 'completion' = 'completion',
  27. }
  28. export enum ModelModeType {
  29. 'chat' = 'chat',
  30. 'completion' = 'completion',
  31. 'unset' = '',
  32. }
  33. export enum RETRIEVE_TYPE {
  34. oneWay = 'single',
  35. multiWay = 'multiple',
  36. }
  37. export enum RETRIEVE_METHOD {
  38. semantic = 'semantic_search',
  39. fullText = 'full_text_search',
  40. hybrid = 'hybrid_search',
  41. invertedIndex = 'invertedIndex',
  42. keywordSearch = 'keyword_search',
  43. }
  44. export type VariableInput = {
  45. key: string
  46. name: string
  47. value: string
  48. }
  49. /**
  50. * App modes
  51. */
  52. export const AppModes = ['advanced-chat', 'agent-chat', 'chat', 'completion', 'workflow'] as const
  53. export type AppMode = typeof AppModes[number]
  54. /**
  55. * Variable type
  56. */
  57. export const VariableTypes = ['string', 'number', 'select'] as const
  58. export type VariableType = typeof VariableTypes[number]
  59. /**
  60. * Prompt variable parameter
  61. */
  62. export type PromptVariable = {
  63. /** Variable key */
  64. key: string
  65. /** Variable name */
  66. name: string
  67. /** Type */
  68. type: VariableType
  69. required: boolean
  70. /** Enumeration of single-selection drop-down values */
  71. options?: string[]
  72. max_length?: number
  73. }
  74. export type TextTypeFormItem = {
  75. default: string
  76. label: string
  77. variable: string
  78. required: boolean
  79. max_length: number
  80. }
  81. export type SelectTypeFormItem = {
  82. default: string
  83. label: string
  84. variable: string
  85. required: boolean
  86. options: string[]
  87. }
  88. export type ParagraphTypeFormItem = {
  89. default: string
  90. label: string
  91. variable: string
  92. required: boolean
  93. }
  94. /**
  95. * User Input Form Item
  96. */
  97. export type UserInputFormItem = {
  98. 'text-input': TextTypeFormItem
  99. } | {
  100. 'select': SelectTypeFormItem
  101. } | {
  102. 'paragraph': TextTypeFormItem
  103. }
  104. export type AgentTool = {
  105. provider_id: string
  106. provider_type: CollectionType
  107. provider_name: string
  108. tool_name: string
  109. tool_label: string
  110. tool_parameters: Record<string, any>
  111. enabled: boolean
  112. isDeleted?: boolean
  113. notAuthor?: boolean
  114. }
  115. export type ToolItem = {
  116. dataset: {
  117. enabled: boolean
  118. id: string
  119. }
  120. } | {
  121. 'sensitive-word-avoidance': {
  122. enabled: boolean
  123. words: string[]
  124. canned_response: string
  125. }
  126. } | AgentTool
  127. export enum AgentStrategy {
  128. functionCall = 'function_call',
  129. react = 'react',
  130. }
  131. export type CompletionParams = {
  132. /** Maximum number of tokens in the answer message returned by Completion */
  133. max_tokens: number
  134. /**
  135. * A number between 0 and 2.
  136. * The larger the number, the more random the result;
  137. * otherwise, the more deterministic.
  138. * When in use, choose either `temperature` or `top_p`.
  139. * Default is 1.
  140. */
  141. temperature: number
  142. /**
  143. * Represents the proportion of probability mass samples to take,
  144. * e.g., 0.1 means taking the top 10% probability mass samples.
  145. * The determinism between the samples is basically consistent.
  146. * Among these results, the `top_p` probability mass results are taken.
  147. * When in use, choose either `temperature` or `top_p`.
  148. * Default is 1.
  149. */
  150. top_p: number
  151. /** When enabled, the Completion Text will concatenate the Prompt content together and return it. */
  152. echo: boolean
  153. /**
  154. * Specify up to 4 to automatically stop generating before the text specified in `stop`.
  155. * Suitable for use in chat mode.
  156. * For example, specify "Q" and "A",
  157. * and provide some Q&A examples as context,
  158. * and the model will give out in Q&A format and stop generating before Q&A.
  159. */
  160. stop: string[]
  161. /**
  162. * A number between -2.0 and 2.0.
  163. * The larger the value, the less the model will repeat topics and the more it will provide new topics.
  164. */
  165. presence_penalty: number
  166. /**
  167. * A number between -2.0 and 2.0.
  168. * A lower setting will make the model appear less cultured,
  169. * always repeating expressions.
  170. * The difference between `frequency_penalty` and `presence_penalty`
  171. * is that `frequency_penalty` penalizes a word based on its frequency in the training data,
  172. * while `presence_penalty` penalizes a word based on its occurrence in the input text.
  173. */
  174. frequency_penalty: number
  175. }
  176. /**
  177. * Model configuration. The backend type.
  178. */
  179. export type Model = {
  180. /** LLM provider, e.g., OPENAI */
  181. provider: string
  182. /** Model name, e.g, gpt-3.5.turbo */
  183. name: string
  184. mode: ModelModeType
  185. /** Default Completion call parameters */
  186. completion_params: CompletionParams
  187. }
  188. export type ModelConfig = {
  189. opening_statement: string
  190. suggested_questions?: string[]
  191. pre_prompt: string
  192. prompt_type: PromptMode
  193. chat_prompt_config: ChatPromptConfig | {}
  194. completion_prompt_config: CompletionPromptConfig | {}
  195. user_input_form: UserInputFormItem[]
  196. dataset_query_variable?: string
  197. more_like_this: {
  198. enabled?: boolean
  199. }
  200. suggested_questions_after_answer: {
  201. enabled: boolean
  202. }
  203. speech_to_text: {
  204. enabled: boolean
  205. }
  206. text_to_speech: {
  207. enabled: boolean
  208. voice?: string
  209. language?: string
  210. autoPlay?: TtsAutoPlay
  211. }
  212. retriever_resource: {
  213. enabled: boolean
  214. }
  215. sensitive_word_avoidance: {
  216. enabled: boolean
  217. }
  218. annotation_reply?: AnnotationReplyConfig
  219. agent_mode: {
  220. enabled: boolean
  221. strategy?: AgentStrategy
  222. tools: ToolItem[]
  223. }
  224. model: Model
  225. dataset_configs: DatasetConfigs
  226. file_upload?: {
  227. image: VisionSettings
  228. } & UploadFileSetting
  229. files?: VisionFile[]
  230. created_at?: number
  231. updated_at?: number
  232. }
  233. export type Language = typeof LanguagesSupported[number]
  234. /**
  235. * Web Application Configuration
  236. */
  237. export type SiteConfig = {
  238. /** Application URL Identifier: `http://dify.app/{access_token}` */
  239. access_token: string
  240. /** Public Title */
  241. title: string
  242. /** Application Description will be shown in the Client */
  243. description: string
  244. /** Define the color in hex for different elements of the chatbot, such as:
  245. * The header, the button , etc.
  246. */
  247. chat_color_theme: string
  248. /** Invert the color of the theme set in chat_color_theme */
  249. chat_color_theme_inverted: boolean
  250. /** Author */
  251. author: string
  252. /** User Support Email Address */
  253. support_email: string
  254. /**
  255. * Default Language, e.g. zh-Hans, en-US
  256. * Use standard RFC 4646, see https://www.ruanyifeng.com/blog/2008/02/codes_for_language_names.html
  257. */
  258. default_language: Language
  259. /** Custom Domain */
  260. customize_domain: string
  261. /** Theme */
  262. theme: string
  263. /** Custom Token strategy Whether Terminal Users can choose their OpenAI Key */
  264. customize_token_strategy: 'must' | 'allow' | 'not_allow'
  265. /** Is Prompt Public */
  266. prompt_public: boolean
  267. /** Web API and APP Base Domain Name */
  268. app_base_url: string
  269. /** Copyright */
  270. copyright: string
  271. /** Privacy Policy */
  272. privacy_policy: string
  273. /** Custom Disclaimer */
  274. custom_disclaimer: string
  275. icon_type: AppIconType | null
  276. icon: string
  277. icon_background: string | null
  278. icon_url: string | null
  279. show_workflow_steps: boolean
  280. use_icon_as_answer_icon: boolean
  281. }
  282. export type AppIconType = 'image' | 'emoji'
  283. /**
  284. * App
  285. */
  286. export type App = {
  287. /** App ID */
  288. id: string
  289. /** Name */
  290. name: string
  291. /** Description */
  292. description: string
  293. /**
  294. * Icon Type
  295. * @default 'emoji'
  296. */
  297. icon_type: AppIconType | null
  298. /** Icon, stores file ID if icon_type is 'image' */
  299. icon: string
  300. /** Icon Background, only available when icon_type is null or 'emoji' */
  301. icon_background: string | null
  302. /** Icon URL, only available when icon_type is 'image' */
  303. icon_url: string | null
  304. /** Whether to use app icon as answer icon */
  305. use_icon_as_answer_icon: boolean
  306. /** Mode */
  307. mode: AppMode
  308. /** Enable web app */
  309. enable_site: boolean
  310. /** Enable web API */
  311. enable_api: boolean
  312. /** API requests per minute, default is 60 */
  313. api_rpm: number
  314. /** API requests per hour, default is 3600 */
  315. api_rph: number
  316. /** Whether it's a demo app */
  317. is_demo: boolean
  318. /** Model configuration */
  319. model_config: ModelConfig
  320. app_model_config: ModelConfig
  321. /** Timestamp of creation */
  322. created_at: number
  323. /** Web Application Configuration */
  324. site: SiteConfig
  325. /** api site url */
  326. api_base_url: string
  327. tags: Tag[]
  328. }
  329. export type AppSSO = {
  330. enable_sso: boolean
  331. }
  332. /**
  333. * App Template
  334. */
  335. export type AppTemplate = {
  336. /** Name */
  337. name: string
  338. /** Description */
  339. description: string
  340. /** Mode */
  341. mode: AppMode
  342. /** Model */
  343. model_config: ModelConfig
  344. }
  345. export enum Resolution {
  346. low = 'low',
  347. high = 'high',
  348. }
  349. export enum TransferMethod {
  350. all = 'all',
  351. local_file = 'local_file',
  352. remote_url = 'remote_url',
  353. }
  354. export enum TtsAutoPlay {
  355. enabled = 'enabled',
  356. disabled = 'disabled',
  357. }
  358. export const ALLOW_FILE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'webp', 'gif']
  359. export type VisionSettings = {
  360. enabled: boolean
  361. number_limits: number
  362. detail: Resolution
  363. transfer_methods: TransferMethod[]
  364. image_file_size_limit?: number | string
  365. }
  366. export type ImageFile = {
  367. type: TransferMethod
  368. _id: string
  369. fileId: string
  370. file?: File
  371. progress: number
  372. url: string
  373. base64Url?: string
  374. deleted?: boolean
  375. }
  376. export type VisionFile = {
  377. id?: string
  378. type: string
  379. transfer_method: TransferMethod
  380. url: string
  381. upload_file_id: string
  382. belongs_to?: string
  383. }
  384. export type RetrievalConfig = {
  385. search_method: RETRIEVE_METHOD
  386. reranking_enable: boolean
  387. reranking_model: {
  388. reranking_provider_name: string
  389. reranking_model_name: string
  390. }
  391. top_k: number
  392. score_threshold_enabled: boolean
  393. score_threshold: number
  394. reranking_mode?: RerankingModeEnum
  395. weights?: {
  396. weight_type: WeightedScoreEnum
  397. vector_setting: {
  398. vector_weight: number
  399. embedding_provider_name: string
  400. embedding_model_name: string
  401. }
  402. keyword_setting: {
  403. keyword_weight: number
  404. }
  405. }
  406. }