app.ts 7.3 KB

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