app.ts 10 KB

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