app.ts 8.9 KB

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