app.ts 9.1 KB

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