app.ts 9.3 KB

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