app.ts 8.3 KB

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