app.ts 8.6 KB

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