app.ts 9.2 KB

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