You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.ts 11KB

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