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. export enum ProviderType {
  4. openai = 'openai',
  5. anthropic = 'anthropic',
  6. azure_openai = 'azure_openai',
  7. replicate = 'replicate',
  8. huggingface_hub = 'huggingface_hub',
  9. minimax = 'minimax',
  10. tongyi = 'tongyi',
  11. spark = 'spark',
  12. }
  13. export enum AppType {
  14. 'chat' = 'chat',
  15. 'completion' = 'completion',
  16. }
  17. export enum ModelModeType {
  18. 'chat' = 'chat',
  19. 'completion' = 'completion',
  20. 'unset' = '',
  21. }
  22. export enum RETRIEVE_TYPE {
  23. oneWay = 'single',
  24. multiWay = 'multiple',
  25. }
  26. export enum RETRIEVE_METHOD {
  27. semantic = 'semantic_search',
  28. fullText = 'full_text_search',
  29. hybrid = 'hybrid_search',
  30. invertedIndex = 'invertedIndex',
  31. }
  32. export type VariableInput = {
  33. key: string
  34. name: string
  35. value: string
  36. }
  37. /**
  38. * App modes
  39. */
  40. export const AppModes = ['completion', 'chat'] as const
  41. export type AppMode = typeof AppModes[number]
  42. /**
  43. * Variable type
  44. */
  45. export const VariableTypes = ['string', 'number', 'select'] as const
  46. export type VariableType = typeof VariableTypes[number]
  47. /**
  48. * Prompt variable parameter
  49. */
  50. export type PromptVariable = {
  51. /** Variable key */
  52. key: string
  53. /** Variable name */
  54. name: string
  55. /** Type */
  56. type: VariableType
  57. required: boolean
  58. /** Enumeration of single-selection drop-down values */
  59. options?: string[]
  60. max_length?: number
  61. }
  62. export type TextTypeFormItem = {
  63. label: string
  64. variable: string
  65. required: boolean
  66. max_length: number
  67. }
  68. export type SelectTypeFormItem = {
  69. label: string
  70. variable: string
  71. required: boolean
  72. options: string[]
  73. }
  74. /**
  75. * User Input Form Item
  76. */
  77. export type UserInputFormItem = {
  78. 'text-input': TextTypeFormItem
  79. } | {
  80. 'select': SelectTypeFormItem
  81. }
  82. export type AgentTool = {
  83. provider_id: string
  84. provider_type: CollectionType
  85. provider_name: string
  86. tool_name: string
  87. tool_label: string
  88. tool_parameters: Record<string, any>
  89. enabled: boolean
  90. isDeleted?: boolean
  91. notAuthor?: boolean
  92. }
  93. export type ToolItem = {
  94. dataset: {
  95. enabled: boolean
  96. id: string
  97. }
  98. } | {
  99. 'sensitive-word-avoidance': {
  100. enabled: boolean
  101. words: string[]
  102. canned_response: string
  103. }
  104. } | AgentTool
  105. export enum AgentStrategy {
  106. functionCall = 'function_call',
  107. react = 'react',
  108. }
  109. /**
  110. * Model configuration. The backend type.
  111. */
  112. export type ModelConfig = {
  113. opening_statement: string
  114. suggested_questions?: string[]
  115. pre_prompt: string
  116. prompt_type: PromptMode
  117. chat_prompt_config: ChatPromptConfig | {}
  118. completion_prompt_config: CompletionPromptConfig | {}
  119. user_input_form: UserInputFormItem[]
  120. dataset_query_variable?: string
  121. more_like_this: {
  122. enabled: boolean
  123. }
  124. suggested_questions_after_answer: {
  125. enabled: boolean
  126. }
  127. speech_to_text: {
  128. enabled: boolean
  129. }
  130. retriever_resource: {
  131. enabled: boolean
  132. }
  133. sensitive_word_avoidance: {
  134. enabled: boolean
  135. }
  136. annotation_reply?: AnnotationReplyConfig
  137. agent_mode: {
  138. enabled: boolean
  139. strategy?: AgentStrategy
  140. tools: ToolItem[]
  141. }
  142. model: {
  143. /** LLM provider, e.g., OPENAI */
  144. provider: string
  145. /** Model name, e.g, gpt-3.5.turbo */
  146. name: string
  147. mode: ModelModeType
  148. /** Default Completion call parameters */
  149. completion_params: {
  150. /** Maximum number of tokens in the answer message returned by Completion */
  151. max_tokens: number
  152. /**
  153. * A number between 0 and 2.
  154. * The larger the number, the more random the result;
  155. * otherwise, the more deterministic.
  156. * When in use, choose either `temperature` or `top_p`.
  157. * Default is 1.
  158. */
  159. temperature: number
  160. /**
  161. * Represents the proportion of probability mass samples to take,
  162. * e.g., 0.1 means taking the top 10% probability mass samples.
  163. * The determinism between the samples is basically consistent.
  164. * Among these results, the `top_p` probability mass results are taken.
  165. * When in use, choose either `temperature` or `top_p`.
  166. * Default is 1.
  167. */
  168. top_p: number
  169. /** When enabled, the Completion Text will concatenate the Prompt content together and return it. */
  170. echo: boolean
  171. /**
  172. * Specify up to 4 to automatically stop generating before the text specified in `stop`.
  173. * Suitable for use in chat mode.
  174. * For example, specify "Q" and "A",
  175. * and provide some Q&A examples as context,
  176. * and the model will give out in Q&A format and stop generating before Q&A.
  177. */
  178. stop: string[]
  179. /**
  180. * A number between -2.0 and 2.0.
  181. * The larger the value, the less the model will repeat topics and the more it will provide new topics.
  182. */
  183. presence_penalty: number
  184. /**
  185. * A number between -2.0 and 2.0.
  186. * A lower setting will make the model appear less cultured,
  187. * always repeating expressions.
  188. * The difference between `frequency_penalty` and `presence_penalty`
  189. * is that `frequency_penalty` penalizes a word based on its frequency in the training data,
  190. * while `presence_penalty` penalizes a word based on its occurrence in the input text.
  191. */
  192. frequency_penalty: number
  193. }
  194. }
  195. dataset_configs: DatasetConfigs
  196. file_upload?: {
  197. image: VisionSettings
  198. }
  199. files?: VisionFile[]
  200. }
  201. export const LanguagesSupported = ['zh-Hans', 'en-US'] as const
  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. }