app.ts 8.4 KB

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