app.ts 9.2 KB

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