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

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