app.ts 8.7 KB

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