app.ts 10 KB

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