index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* eslint-disable import/no-mutable-exports */
  2. import { AppType, ProviderType } from '@/types/app'
  3. const isDevelopment = process.env.NODE_ENV === 'development'
  4. export let apiPrefix = ''
  5. export let publicApiPrefix = ''
  6. // NEXT_PUBLIC_API_PREFIX=/console/api NEXT_PUBLIC_PUBLIC_API_PREFIX=/api npm run start
  7. if (process.env.NEXT_PUBLIC_API_PREFIX && process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX) {
  8. apiPrefix = process.env.NEXT_PUBLIC_API_PREFIX
  9. publicApiPrefix = process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX
  10. }
  11. else if (
  12. globalThis.document?.body?.getAttribute('data-api-prefix')
  13. && globalThis.document?.body?.getAttribute('data-pubic-api-prefix')
  14. ) {
  15. // Not bulild can not get env from process.env.NEXT_PUBLIC_ in browser https://nextjs.org/docs/basic-features/environment-variables#exposing-environment-variables-to-the-browser
  16. apiPrefix = globalThis.document.body.getAttribute('data-api-prefix') as string
  17. publicApiPrefix = globalThis.document.body.getAttribute('data-pubic-api-prefix') as string
  18. }
  19. else {
  20. if (isDevelopment) {
  21. apiPrefix = 'https://cloud.dify.dev/console/api'
  22. publicApiPrefix = 'https://dev.udify.app/api'
  23. }
  24. else {
  25. // const domainParts = globalThis.location?.host?.split('.');
  26. // in production env, the host is dify.app . In other env, the host is [dev].dify.app
  27. // const env = domainParts.length === 2 ? 'ai' : domainParts?.[0];
  28. apiPrefix = '/console/api'
  29. publicApiPrefix = '/api' // avoid browser private mode api cross origin
  30. }
  31. }
  32. export const API_PREFIX: string = apiPrefix
  33. export const PUBLIC_API_PREFIX: string = publicApiPrefix
  34. const EDITION = process.env.NEXT_PUBLIC_EDITION || globalThis.document?.body?.getAttribute('data-public-edition')
  35. export const IS_CE_EDITION = EDITION === 'SELF_HOSTED'
  36. export const MODEL_LIST = [
  37. { id: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo', type: AppType.chat },
  38. { id: 'gpt-3.5-turbo-16k', name: 'gpt-3.5-turbo-16k', type: AppType.chat },
  39. { id: 'gpt-4', name: 'gpt-4', type: AppType.chat }, // 8k version
  40. { id: 'claude-instant-1', name: 'claude-instant-1', type: AppType.chat, provider: ProviderType.anthropic }, // set 30k
  41. { id: 'claude-2', name: 'claude-2', type: AppType.chat, provider: ProviderType.anthropic }, // set 30k
  42. { id: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo', type: AppType.completion },
  43. { id: 'gpt-3.5-turbo-16k', name: 'gpt-3.5-turbo-16k', type: AppType.completion },
  44. { id: 'text-davinci-003', name: 'text-davinci-003', type: AppType.completion },
  45. { id: 'gpt-4', name: 'gpt-4', type: AppType.completion }, // 8k version
  46. { id: 'claude-instant-1', name: 'claude-instant-1', type: AppType.completion, provider: ProviderType.anthropic }, // set 30k
  47. { id: 'claude-2', name: 'claude-2', type: AppType.completion, provider: ProviderType.anthropic }, // set 30k
  48. ]
  49. const UNIVERSAL_CHAT_MODEL_ID_LIST = ['gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-4', 'claude-2']
  50. export const UNIVERSAL_CHAT_MODEL_LIST = MODEL_LIST.filter(({ id, type }) => UNIVERSAL_CHAT_MODEL_ID_LIST.includes(id) && (type === AppType.chat))
  51. export const TONE_LIST = [
  52. {
  53. id: 1,
  54. name: 'Creative',
  55. config: {
  56. temperature: 0.8,
  57. top_p: 0.9,
  58. presence_penalty: 0.1,
  59. frequency_penalty: 0.1,
  60. },
  61. },
  62. {
  63. id: 2,
  64. name: 'Balanced',
  65. config: {
  66. temperature: 0.5,
  67. top_p: 0.85,
  68. presence_penalty: 0.2,
  69. frequency_penalty: 0.3,
  70. },
  71. },
  72. {
  73. id: 3,
  74. name: 'Precise',
  75. config: {
  76. temperature: 0.2,
  77. top_p: 0.75,
  78. presence_penalty: 0.5,
  79. frequency_penalty: 0.5,
  80. },
  81. },
  82. {
  83. id: 4,
  84. name: 'Custom',
  85. },
  86. ]
  87. export const LOCALE_COOKIE_NAME = 'locale'
  88. export const DEFAULT_VALUE_MAX_LEN = 48
  89. export const zhRegex = /^[\u4E00-\u9FA5]$/m
  90. export const emojiRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/m
  91. export const emailRegex = /^[\w\.-]+@([\w-]+\.)+[\w-]{2,}$/m
  92. const MAX_ZN_VAR_NAME_LENGHT = 8
  93. const MAX_EN_VAR_VALUE_LENGHT = 16
  94. export const getMaxVarNameLength = (value: string) => {
  95. if (zhRegex.test(value))
  96. return MAX_ZN_VAR_NAME_LENGHT
  97. return MAX_EN_VAR_VALUE_LENGHT
  98. }
  99. export const MAX_VAR_KEY_LENGHT = 16
  100. export const VAR_ITEM_TEMPLATE = {
  101. key: '',
  102. name: '',
  103. type: 'string',
  104. max_length: DEFAULT_VALUE_MAX_LEN,
  105. required: true,
  106. }
  107. export const appDefaultIconBackground = '#D5F5F6'
  108. export const NEED_REFRESH_APP_LIST_KEY = 'needRefreshAppList'
  109. export const SPARK_FREE_QUOTA_PENDING = 'sparkFreeQuotaPending'