app.ts 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. }
  259. /**
  260. * App
  261. */
  262. export type App = {
  263. /** App ID */
  264. id: string
  265. /** Name */
  266. name: string
  267. /** Description */
  268. description: string
  269. /** Icon */
  270. icon: string
  271. /** Icon Background */
  272. icon_background: string
  273. /** Mode */
  274. mode: AppMode
  275. /** Enable web app */
  276. enable_site: boolean
  277. /** Enable web API */
  278. enable_api: boolean
  279. /** API requests per minute, default is 60 */
  280. api_rpm: number
  281. /** API requests per hour, default is 3600 */
  282. api_rph: number
  283. /** Whether it's a demo app */
  284. is_demo: boolean
  285. /** Model configuration */
  286. model_config: ModelConfig
  287. app_model_config: ModelConfig
  288. /** Timestamp of creation */
  289. created_at: number
  290. /** Web Application Configuration */
  291. site: SiteConfig
  292. /** api site url */
  293. api_base_url: string
  294. tags: Tag[]
  295. }
  296. /**
  297. * App Template
  298. */
  299. export type AppTemplate = {
  300. /** Name */
  301. name: string
  302. /** Description */
  303. description: string
  304. /** Mode */
  305. mode: AppMode
  306. /** Model */
  307. model_config: ModelConfig
  308. }
  309. export enum Resolution {
  310. low = 'low',
  311. high = 'high',
  312. }
  313. export enum TransferMethod {
  314. all = 'all',
  315. local_file = 'local_file',
  316. remote_url = 'remote_url',
  317. }
  318. export const ALLOW_FILE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'webp', 'gif']
  319. export type VisionSettings = {
  320. enabled: boolean
  321. number_limits: number
  322. detail: Resolution
  323. transfer_methods: TransferMethod[]
  324. image_file_size_limit?: number | string
  325. }
  326. export type ImageFile = {
  327. type: TransferMethod
  328. _id: string
  329. fileId: string
  330. file?: File
  331. progress: number
  332. url: string
  333. base64Url?: string
  334. deleted?: boolean
  335. }
  336. export type VisionFile = {
  337. id?: string
  338. type: string
  339. transfer_method: TransferMethod
  340. url: string
  341. upload_file_id: string
  342. belongs_to?: string
  343. }
  344. export type RetrievalConfig = {
  345. search_method: RETRIEVE_METHOD
  346. reranking_enable: boolean
  347. reranking_model: {
  348. reranking_provider_name: string
  349. reranking_model_name: string
  350. }
  351. top_k: number
  352. score_threshold_enabled: boolean
  353. score_threshold: number
  354. }