app.ts 7.8 KB

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