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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. /**
  296. * Icon Type
  297. * @default 'emoji'
  298. */
  299. icon_type: AppIconType | null
  300. /** Icon, stores file ID if icon_type is 'image' */
  301. icon: string
  302. /** Icon Background, only available when icon_type is null or 'emoji' */
  303. icon_background: string | null
  304. /** Icon URL, only available when icon_type is 'image' */
  305. icon_url: string | null
  306. /** Whether to use app icon as answer icon */
  307. use_icon_as_answer_icon: boolean
  308. /** Mode */
  309. mode: AppMode
  310. /** Enable web app */
  311. enable_site: boolean
  312. /** Enable web API */
  313. enable_api: boolean
  314. /** API requests per minute, default is 60 */
  315. api_rpm: number
  316. /** API requests per hour, default is 3600 */
  317. api_rph: number
  318. /** Whether it's a demo app */
  319. is_demo: boolean
  320. /** Model configuration */
  321. model_config: ModelConfig
  322. app_model_config: ModelConfig
  323. /** Timestamp of creation */
  324. created_at: number
  325. /** Web Application Configuration */
  326. site: SiteConfig
  327. /** api site url */
  328. api_base_url: string
  329. tags: Tag[]
  330. workflow?: {
  331. id: string
  332. created_at: number
  333. created_by?: string
  334. updated_at: number
  335. updated_by?: string
  336. }
  337. /** access control */
  338. access_mode: AccessMode
  339. }
  340. export type AppSSO = {
  341. enable_sso: boolean
  342. }
  343. /**
  344. * App Template
  345. */
  346. export type AppTemplate = {
  347. /** Name */
  348. name: string
  349. /** Description */
  350. description: string
  351. /** Mode */
  352. mode: AppMode
  353. /** Model */
  354. model_config: ModelConfig
  355. }
  356. export enum Resolution {
  357. low = 'low',
  358. high = 'high',
  359. }
  360. export enum TransferMethod {
  361. all = 'all',
  362. local_file = 'local_file',
  363. remote_url = 'remote_url',
  364. }
  365. export enum TtsAutoPlay {
  366. enabled = 'enabled',
  367. disabled = 'disabled',
  368. }
  369. export const ALLOW_FILE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'webp', 'gif']
  370. export type VisionSettings = {
  371. enabled: boolean
  372. number_limits: number
  373. detail: Resolution
  374. transfer_methods: TransferMethod[]
  375. image_file_size_limit?: number | string
  376. }
  377. export type ImageFile = {
  378. type: TransferMethod
  379. _id: string
  380. fileId: string
  381. file?: File
  382. progress: number
  383. url: string
  384. base64Url?: string
  385. deleted?: boolean
  386. }
  387. export type VisionFile = {
  388. id?: string
  389. type: string
  390. transfer_method: TransferMethod
  391. url: string
  392. upload_file_id: string
  393. belongs_to?: string
  394. }
  395. export type RetrievalConfig = {
  396. search_method: RETRIEVE_METHOD
  397. reranking_enable: boolean
  398. reranking_model: {
  399. reranking_provider_name: string
  400. reranking_model_name: string
  401. }
  402. top_k: number
  403. score_threshold_enabled: boolean
  404. score_threshold: number
  405. reranking_mode?: RerankingModeEnum
  406. weights?: {
  407. weight_type: WeightedScoreEnum
  408. vector_setting: {
  409. vector_weight: number
  410. embedding_provider_name: string
  411. embedding_model_name: string
  412. }
  413. keyword_setting: {
  414. keyword_weight: number
  415. }
  416. }
  417. }