app.ts 6.5 KB

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