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

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