選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

app.ts 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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-config/language'
  4. import type { Tag } from '@/app/components/base/tag-management/constant'
  5. import type {
  6. RerankingModeEnum,
  7. WeightedScoreEnum,
  8. } from '@/models/datasets'
  9. import type { UploadFileSetting } from '@/app/components/workflow/types'
  10. import type { AccessMode } from '@/models/access-control'
  11. export enum Theme {
  12. light = 'light',
  13. dark = 'dark',
  14. system = 'system',
  15. }
  16. export enum ProviderType {
  17. openai = 'openai',
  18. anthropic = 'anthropic',
  19. azure_openai = 'azure_openai',
  20. replicate = 'replicate',
  21. huggingface_hub = 'huggingface_hub',
  22. minimax = 'minimax',
  23. tongyi = 'tongyi',
  24. spark = 'spark',
  25. }
  26. export enum AppType {
  27. chat = 'chat',
  28. completion = 'completion',
  29. }
  30. export enum ModelModeType {
  31. chat = 'chat',
  32. completion = 'completion',
  33. unset = '',
  34. }
  35. export enum RETRIEVE_TYPE {
  36. oneWay = 'single',
  37. multiWay = 'multiple',
  38. }
  39. export enum RETRIEVE_METHOD {
  40. semantic = 'semantic_search',
  41. fullText = 'full_text_search',
  42. hybrid = 'hybrid_search',
  43. invertedIndex = 'invertedIndex',
  44. keywordSearch = 'keyword_search',
  45. }
  46. export type VariableInput = {
  47. key: string
  48. name: string
  49. value: string
  50. }
  51. /**
  52. * App modes
  53. */
  54. export const AppModes = ['advanced-chat', 'agent-chat', 'chat', 'completion', 'workflow'] as const
  55. export type AppMode = typeof AppModes[number]
  56. /**
  57. * Variable type
  58. */
  59. export const VariableTypes = ['string', 'number', 'select'] as const
  60. export type VariableType = typeof VariableTypes[number]
  61. /**
  62. * Prompt variable parameter
  63. */
  64. export type PromptVariable = {
  65. /** Variable key */
  66. key: string
  67. /** Variable name */
  68. name: string
  69. /** Type */
  70. type: VariableType
  71. required: boolean
  72. /** Enumeration of single-selection drop-down values */
  73. options?: string[]
  74. max_length?: number
  75. }
  76. export type TextTypeFormItem = {
  77. default: string
  78. label: string
  79. variable: string
  80. required: boolean
  81. max_length: number
  82. hide: boolean
  83. }
  84. export type SelectTypeFormItem = {
  85. default: string
  86. label: string
  87. variable: string
  88. required: boolean
  89. options: string[]
  90. hide: boolean
  91. }
  92. /**
  93. * User Input Form Item
  94. */
  95. export type UserInputFormItem = {
  96. 'text-input': TextTypeFormItem
  97. } | {
  98. select: SelectTypeFormItem
  99. } | {
  100. paragraph: TextTypeFormItem
  101. }
  102. export type AgentTool = {
  103. provider_id: string
  104. provider_type: CollectionType
  105. provider_name: string
  106. tool_name: string
  107. tool_label: string
  108. tool_parameters: Record<string, any>
  109. enabled: boolean
  110. isDeleted?: boolean
  111. notAuthor?: boolean
  112. credential_id?: string
  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. } & UploadFileSetting
  228. files?: VisionFile[]
  229. created_at?: number
  230. updated_at?: number
  231. }
  232. export type Language = typeof LanguagesSupported[number]
  233. /**
  234. * Web Application Configuration
  235. */
  236. export type SiteConfig = {
  237. /** Application URL Identifier: `http://dify.app/{access_token}` */
  238. access_token: string
  239. /** Public Title */
  240. title: string
  241. /** Application Description will be shown in the Client */
  242. description: string
  243. /** Define the color in hex for different elements of the chatbot, such as:
  244. * The header, the button , etc.
  245. */
  246. chat_color_theme: string
  247. /** Invert the color of the theme set in chat_color_theme */
  248. chat_color_theme_inverted: boolean
  249. /** Author */
  250. author: string
  251. /** User Support Email Address */
  252. support_email: string
  253. /**
  254. * Default Language, e.g. zh-Hans, en-US
  255. * Use standard RFC 4646, see https://www.ruanyifeng.com/blog/2008/02/codes_for_language_names.html
  256. */
  257. default_language: Language
  258. /** Custom Domain */
  259. customize_domain: string
  260. /** Theme */
  261. theme: string
  262. /** Custom Token strategy Whether Terminal Users can choose their OpenAI Key */
  263. customize_token_strategy: 'must' | 'allow' | 'not_allow'
  264. /** Is Prompt Public */
  265. prompt_public: boolean
  266. /** Web API and APP Base Domain Name */
  267. app_base_url: string
  268. /** Copyright */
  269. copyright: string
  270. /** Privacy Policy */
  271. privacy_policy: string
  272. /** Custom Disclaimer */
  273. custom_disclaimer: string
  274. icon_type: AppIconType | null
  275. icon: string
  276. icon_background: string | null
  277. icon_url: string | null
  278. show_workflow_steps: boolean
  279. use_icon_as_answer_icon: boolean
  280. }
  281. export type AppIconType = 'image' | 'emoji'
  282. /**
  283. * App
  284. */
  285. export type App = {
  286. /** App ID */
  287. id: string
  288. /** Name */
  289. name: string
  290. /** Description */
  291. description: string
  292. /** Author Name */
  293. author_name: string;
  294. /**
  295. * Icon Type
  296. * @default 'emoji'
  297. */
  298. icon_type: AppIconType | null
  299. /** Icon, stores file ID if icon_type is 'image' */
  300. icon: string
  301. /** Icon Background, only available when icon_type is null or 'emoji' */
  302. icon_background: string | null
  303. /** Icon URL, only available when icon_type is 'image' */
  304. icon_url: string | null
  305. /** Whether to use app icon as answer icon */
  306. use_icon_as_answer_icon: boolean
  307. /** Mode */
  308. mode: AppMode
  309. /** Enable web app */
  310. enable_site: boolean
  311. /** Enable web API */
  312. enable_api: boolean
  313. /** API requests per minute, default is 60 */
  314. api_rpm: number
  315. /** API requests per hour, default is 3600 */
  316. api_rph: number
  317. /** Whether it's a demo app */
  318. is_demo: boolean
  319. /** Model configuration */
  320. model_config: ModelConfig
  321. app_model_config: ModelConfig
  322. /** Timestamp of creation */
  323. created_at: number
  324. /** Timestamp of update */
  325. updated_at: number
  326. /** Web Application Configuration */
  327. site: SiteConfig
  328. /** api site url */
  329. api_base_url: string
  330. tags: Tag[]
  331. workflow?: {
  332. id: string
  333. created_at: number
  334. created_by?: string
  335. updated_at: number
  336. updated_by?: string
  337. }
  338. /** access control */
  339. access_mode: AccessMode
  340. max_active_requests?: number | null
  341. }
  342. export type AppSSO = {
  343. enable_sso: boolean
  344. }
  345. /**
  346. * App Template
  347. */
  348. export type AppTemplate = {
  349. /** Name */
  350. name: string
  351. /** Description */
  352. description: string
  353. /** Mode */
  354. mode: AppMode
  355. /** Model */
  356. model_config: ModelConfig
  357. }
  358. export enum Resolution {
  359. low = 'low',
  360. high = 'high',
  361. }
  362. export enum TransferMethod {
  363. all = 'all',
  364. local_file = 'local_file',
  365. remote_url = 'remote_url',
  366. }
  367. export enum TtsAutoPlay {
  368. enabled = 'enabled',
  369. disabled = 'disabled',
  370. }
  371. export const ALLOW_FILE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'webp', 'gif']
  372. export type VisionSettings = {
  373. enabled: boolean
  374. number_limits: number
  375. detail: Resolution
  376. transfer_methods: TransferMethod[]
  377. image_file_size_limit?: number | string
  378. }
  379. export type ImageFile = {
  380. type: TransferMethod
  381. _id: string
  382. fileId: string
  383. file?: File
  384. progress: number
  385. url: string
  386. base64Url?: string
  387. deleted?: boolean
  388. }
  389. export type VisionFile = {
  390. id?: string
  391. type: string
  392. transfer_method: TransferMethod
  393. url: string
  394. upload_file_id: string
  395. belongs_to?: string
  396. }
  397. export type RetrievalConfig = {
  398. search_method: RETRIEVE_METHOD
  399. reranking_enable: boolean
  400. reranking_model: {
  401. reranking_provider_name: string
  402. reranking_model_name: string
  403. }
  404. top_k: number
  405. score_threshold_enabled: boolean
  406. score_threshold: number
  407. reranking_mode?: RerankingModeEnum
  408. weights?: {
  409. weight_type: WeightedScoreEnum
  410. vector_setting: {
  411. vector_weight: number
  412. embedding_provider_name: string
  413. embedding_model_name: string
  414. }
  415. keyword_setting: {
  416. keyword_weight: number
  417. }
  418. }
  419. }