app.ts 8.6 KB

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