constant.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. export const OWNER = "ChatGPTNextWeb";
  2. export const REPO = "ChatGPT-Next-Web";
  3. export const REPO_URL = `https://github.com/${OWNER}/${REPO}`;
  4. export const PLUGINS_REPO_URL = `https://github.com/${OWNER}/NextChat-Awesome-Plugins`;
  5. export const ISSUE_URL = `https://github.com/${OWNER}/${REPO}/issues`;
  6. export const UPDATE_URL = `${REPO_URL}#keep-updated`;
  7. export const RELEASE_URL = `${REPO_URL}/releases`;
  8. export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?per_page=1`;
  9. export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`;
  10. export const RUNTIME_CONFIG_DOM = "danger-runtime-config";
  11. export const STABILITY_BASE_URL = "https://api.stability.ai";
  12. export const OPENAI_BASE_URL = "https://api.openai.com";
  13. export const ANTHROPIC_BASE_URL = "https://api.anthropic.com";
  14. export const GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/";
  15. export const BAIDU_BASE_URL = "https://aip.baidubce.com";
  16. export const BAIDU_OATUH_URL = `${BAIDU_BASE_URL}/oauth/2.0/token`;
  17. export const BYTEDANCE_BASE_URL = "https://ark.cn-beijing.volces.com";
  18. export const ALIBABA_BASE_URL = "https://dashscope.aliyuncs.com/api/";
  19. export const TENCENT_BASE_URL = "https://hunyuan.tencentcloudapi.com";
  20. export const MOONSHOT_BASE_URL = "https://api.moonshot.cn";
  21. export const IFLYTEK_BASE_URL = "https://spark-api-open.xf-yun.com";
  22. export const XAI_BASE_URL = "https://api.x.ai";
  23. export const CHATGLM_BASE_URL = "https://open.bigmodel.cn";
  24. export const CACHE_URL_PREFIX = "/api/cache";
  25. export const UPLOAD_URL = `${CACHE_URL_PREFIX}/upload`;
  26. export enum Path {
  27. Home = "/",
  28. Chat = "/chat",
  29. Settings = "/settings",
  30. NewChat = "/new-chat",
  31. Masks = "/masks",
  32. Plugins = "/plugins",
  33. Auth = "/auth",
  34. Sd = "/sd",
  35. SdNew = "/sd-new",
  36. Artifacts = "/artifacts",
  37. SearchChat = "/search-chat",
  38. }
  39. export enum ApiPath {
  40. Cors = "",
  41. Azure = "/api/azure",
  42. OpenAI = "/api/openai",
  43. Anthropic = "/api/anthropic",
  44. Google = "/api/google",
  45. Baidu = "/api/baidu",
  46. ByteDance = "/api/bytedance",
  47. Alibaba = "/api/alibaba",
  48. Tencent = "/api/tencent",
  49. Moonshot = "/api/moonshot",
  50. Iflytek = "/api/iflytek",
  51. Stability = "/api/stability",
  52. Artifacts = "/api/artifacts",
  53. XAI = "/api/xai",
  54. ChatGLM = "/api/chatglm",
  55. }
  56. export enum SlotID {
  57. AppBody = "app-body",
  58. CustomModel = "custom-model",
  59. }
  60. export enum FileName {
  61. Masks = "masks.json",
  62. Prompts = "prompts.json",
  63. }
  64. export enum StoreKey {
  65. Chat = "chat-next-web-store",
  66. Plugin = "chat-next-web-plugin",
  67. Access = "access-control",
  68. Config = "app-config",
  69. Mask = "mask-store",
  70. Prompt = "prompt-store",
  71. Update = "chat-update",
  72. Sync = "sync",
  73. SdList = "sd-list",
  74. }
  75. export const DEFAULT_SIDEBAR_WIDTH = 300;
  76. export const MAX_SIDEBAR_WIDTH = 500;
  77. export const MIN_SIDEBAR_WIDTH = 230;
  78. export const NARROW_SIDEBAR_WIDTH = 100;
  79. export const ACCESS_CODE_PREFIX = "nk-";
  80. export const LAST_INPUT_KEY = "last-input";
  81. export const UNFINISHED_INPUT = (id: string) => "unfinished-input-" + id;
  82. export const STORAGE_KEY = "chatgpt-next-web";
  83. export const REQUEST_TIMEOUT_MS = 60000;
  84. export const EXPORT_MESSAGE_CLASS_NAME = "export-markdown";
  85. export enum ServiceProvider {
  86. OpenAI = "OpenAI",
  87. Azure = "Azure",
  88. Google = "Google",
  89. Anthropic = "Anthropic",
  90. Baidu = "Baidu",
  91. ByteDance = "ByteDance",
  92. Alibaba = "Alibaba",
  93. Tencent = "Tencent",
  94. Moonshot = "Moonshot",
  95. Stability = "Stability",
  96. Iflytek = "Iflytek",
  97. XAI = "XAI",
  98. ChatGLM = "ChatGLM",
  99. }
  100. // Google API safety settings, see https://ai.google.dev/gemini-api/docs/safety-settings
  101. // BLOCK_NONE will not block any content, and BLOCK_ONLY_HIGH will block only high-risk content.
  102. export enum GoogleSafetySettingsThreshold {
  103. BLOCK_NONE = "BLOCK_NONE",
  104. BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH",
  105. BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE",
  106. BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE",
  107. }
  108. export enum ModelProvider {
  109. Stability = "Stability",
  110. GPT = "GPT",
  111. GeminiPro = "GeminiPro",
  112. Claude = "Claude",
  113. Ernie = "Ernie",
  114. Doubao = "Doubao",
  115. Qwen = "Qwen",
  116. Hunyuan = "Hunyuan",
  117. Moonshot = "Moonshot",
  118. Iflytek = "Iflytek",
  119. XAI = "XAI",
  120. ChatGLM = "ChatGLM",
  121. }
  122. export const Stability = {
  123. GeneratePath: "v2beta/stable-image/generate",
  124. ExampleEndpoint: "https://api.stability.ai",
  125. };
  126. export const Anthropic = {
  127. ChatPath: "v1/messages",
  128. ChatPath1: "v1/complete",
  129. ExampleEndpoint: "https://api.anthropic.com",
  130. Vision: "2023-06-01",
  131. };
  132. export const OpenaiPath = {
  133. ChatPath: "v1/chat/completions",
  134. SpeechPath: "v1/audio/speech",
  135. ImagePath: "v1/images/generations",
  136. UsagePath: "dashboard/billing/usage",
  137. SubsPath: "dashboard/billing/subscription",
  138. ListModelPath: "v1/models",
  139. };
  140. export const Azure = {
  141. ChatPath: (deployName: string, apiVersion: string) =>
  142. `deployments/${deployName}/chat/completions?api-version=${apiVersion}`,
  143. // https://<your_resource_name>.openai.azure.com/openai/deployments/<your_deployment_name>/images/generations?api-version=<api_version>
  144. ImagePath: (deployName: string, apiVersion: string) =>
  145. `deployments/${deployName}/images/generations?api-version=${apiVersion}`,
  146. ExampleEndpoint: "https://{resource-url}/openai",
  147. };
  148. export const Google = {
  149. ExampleEndpoint: "https://generativelanguage.googleapis.com/",
  150. ChatPath: (modelName: string) =>
  151. `v1beta/models/${modelName}:streamGenerateContent`,
  152. };
  153. export const Baidu = {
  154. ExampleEndpoint: BAIDU_BASE_URL,
  155. ChatPath: (modelName: string) => {
  156. let endpoint = modelName;
  157. if (modelName === "ernie-4.0-8k") {
  158. endpoint = "completions_pro";
  159. }
  160. if (modelName === "ernie-4.0-8k-preview-0518") {
  161. endpoint = "completions_adv_pro";
  162. }
  163. if (modelName === "ernie-3.5-8k") {
  164. endpoint = "completions";
  165. }
  166. if (modelName === "ernie-speed-8k") {
  167. endpoint = "ernie_speed";
  168. }
  169. return `rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${endpoint}`;
  170. },
  171. };
  172. export const ByteDance = {
  173. ExampleEndpoint: "https://ark.cn-beijing.volces.com/api/",
  174. ChatPath: "api/v3/chat/completions",
  175. };
  176. export const Alibaba = {
  177. ExampleEndpoint: ALIBABA_BASE_URL,
  178. ChatPath: "v1/services/aigc/text-generation/generation",
  179. };
  180. export const Tencent = {
  181. ExampleEndpoint: TENCENT_BASE_URL,
  182. };
  183. export const Moonshot = {
  184. ExampleEndpoint: MOONSHOT_BASE_URL,
  185. ChatPath: "v1/chat/completions",
  186. };
  187. export const Iflytek = {
  188. ExampleEndpoint: IFLYTEK_BASE_URL,
  189. ChatPath: "v1/chat/completions",
  190. };
  191. export const XAI = {
  192. ExampleEndpoint: XAI_BASE_URL,
  193. ChatPath: "v1/chat/completions",
  194. };
  195. export const ChatGLM = {
  196. ExampleEndpoint: CHATGLM_BASE_URL,
  197. ChatPath: "api/paas/v4/chat/completions",
  198. };
  199. export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
  200. // export const DEFAULT_SYSTEM_TEMPLATE = `
  201. // You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  202. // Knowledge cutoff: {{cutoff}}
  203. // Current model: {{model}}
  204. // Current time: {{time}}
  205. // Latex inline: $x^2$
  206. // Latex block: $$e=mc^2$$
  207. // `;
  208. export const DEFAULT_SYSTEM_TEMPLATE = `
  209. You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  210. Knowledge cutoff: {{cutoff}}
  211. Current model: {{model}}
  212. Current time: {{time}}
  213. Latex inline: \\(x^2\\)
  214. Latex block: $$e=mc^2$$
  215. `;
  216. export const SUMMARIZE_MODEL = "gpt-4o-mini";
  217. export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
  218. export const KnowledgeCutOffDate: Record<string, string> = {
  219. default: "2021-09",
  220. "gpt-4-turbo": "2023-12",
  221. "gpt-4-turbo-2024-04-09": "2023-12",
  222. "gpt-4-turbo-preview": "2023-12",
  223. "gpt-4o": "2023-10",
  224. "gpt-4o-2024-05-13": "2023-10",
  225. "gpt-4o-2024-08-06": "2023-10",
  226. "gpt-4o-2024-11-20": "2023-10",
  227. "chatgpt-4o-latest": "2023-10",
  228. "gpt-4o-mini": "2023-10",
  229. "gpt-4o-mini-2024-07-18": "2023-10",
  230. "gpt-4-vision-preview": "2023-04",
  231. "o1-mini": "2023-10",
  232. "o1-preview": "2023-10",
  233. // After improvements,
  234. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
  235. "gemini-pro": "2023-12",
  236. "gemini-pro-vision": "2023-12",
  237. };
  238. export const DEFAULT_TTS_ENGINE = "OpenAI-TTS";
  239. export const DEFAULT_TTS_ENGINES = ["OpenAI-TTS", "Edge-TTS"];
  240. export const DEFAULT_TTS_MODEL = "tts-1";
  241. export const DEFAULT_TTS_VOICE = "alloy";
  242. export const DEFAULT_TTS_MODELS = ["tts-1", "tts-1-hd"];
  243. export const DEFAULT_TTS_VOICES = [
  244. "alloy",
  245. "echo",
  246. "fable",
  247. "onyx",
  248. "nova",
  249. "shimmer",
  250. ];
  251. export const VISION_MODEL_REGEXES = [
  252. /vision/,
  253. /gpt-4o/,
  254. /claude-3/,
  255. /gemini-1\.5/,
  256. /gemini-exp/,
  257. /learnlm/,
  258. /qwen-vl/,
  259. /qwen2-vl/,
  260. /gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
  261. /^dall-e-3$/, // Matches exactly "dall-e-3"
  262. ];
  263. export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
  264. const openaiModels = [
  265. "gpt-3.5-turbo",
  266. "gpt-3.5-turbo-1106",
  267. "gpt-3.5-turbo-0125",
  268. "gpt-4",
  269. "gpt-4-0613",
  270. "gpt-4-32k",
  271. "gpt-4-32k-0613",
  272. "gpt-4-turbo",
  273. "gpt-4-turbo-preview",
  274. "gpt-4o",
  275. "gpt-4o-2024-05-13",
  276. "gpt-4o-2024-08-06",
  277. "gpt-4o-2024-11-20",
  278. "chatgpt-4o-latest",
  279. "gpt-4o-mini",
  280. "gpt-4o-mini-2024-07-18",
  281. "gpt-4-vision-preview",
  282. "gpt-4-turbo-2024-04-09",
  283. "gpt-4-1106-preview",
  284. "dall-e-3",
  285. "o1-mini",
  286. "o1-preview",
  287. ];
  288. const googleModels = [
  289. "gemini-1.0-pro",
  290. "gemini-1.5-pro-latest",
  291. "gemini-1.5-flash-latest",
  292. "gemini-exp-1114",
  293. "gemini-exp-1121",
  294. "learnlm-1.5-pro-experimental",
  295. "gemini-pro-vision",
  296. ];
  297. const anthropicModels = [
  298. "claude-instant-1.2",
  299. "claude-2.0",
  300. "claude-2.1",
  301. "claude-3-sonnet-20240229",
  302. "claude-3-opus-20240229",
  303. "claude-3-opus-latest",
  304. "claude-3-haiku-20240307",
  305. "claude-3-5-haiku-20241022",
  306. "claude-3-5-haiku-latest",
  307. "claude-3-5-sonnet-20240620",
  308. "claude-3-5-sonnet-20241022",
  309. "claude-3-5-sonnet-latest",
  310. ];
  311. const baiduModels = [
  312. "ernie-4.0-turbo-8k",
  313. "ernie-4.0-8k",
  314. "ernie-4.0-8k-preview",
  315. "ernie-4.0-8k-preview-0518",
  316. "ernie-4.0-8k-latest",
  317. "ernie-3.5-8k",
  318. "ernie-3.5-8k-0205",
  319. "ernie-speed-128k",
  320. "ernie-speed-8k",
  321. "ernie-lite-8k",
  322. "ernie-tiny-8k",
  323. ];
  324. const bytedanceModels = [
  325. "Doubao-lite-4k",
  326. "Doubao-lite-32k",
  327. "Doubao-lite-128k",
  328. "Doubao-pro-4k",
  329. "Doubao-pro-32k",
  330. "Doubao-pro-128k",
  331. ];
  332. const alibabaModes = [
  333. "qwen-turbo",
  334. "qwen-plus",
  335. "qwen-max",
  336. "qwen-max-0428",
  337. "qwen-max-0403",
  338. "qwen-max-0107",
  339. "qwen-max-longcontext",
  340. ];
  341. const tencentModels = [
  342. "hunyuan-pro",
  343. "hunyuan-standard",
  344. "hunyuan-lite",
  345. "hunyuan-role",
  346. "hunyuan-functioncall",
  347. "hunyuan-code",
  348. "hunyuan-vision",
  349. ];
  350. const moonshotModes = ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"];
  351. const iflytekModels = [
  352. "general",
  353. "generalv3",
  354. "pro-128k",
  355. "generalv3.5",
  356. "4.0Ultra",
  357. ];
  358. const xAIModes = ["grok-beta"];
  359. const chatglmModels = [
  360. "glm-4-plus",
  361. "glm-4-0520",
  362. "glm-4",
  363. "glm-4-air",
  364. "glm-4-airx",
  365. "glm-4-long",
  366. "glm-4-flashx",
  367. "glm-4-flash",
  368. ];
  369. let seq = 1000; // 内置的模型序号生成器从1000开始
  370. export const DEFAULT_MODELS = [
  371. ...openaiModels.map((name) => ({
  372. name,
  373. available: true,
  374. sorted: seq++, // Global sequence sort(index)
  375. provider: {
  376. id: "openai",
  377. providerName: "OpenAI",
  378. providerType: "openai",
  379. sorted: 1, // 这里是固定的,确保顺序与之前内置的版本一致
  380. },
  381. })),
  382. ...openaiModels.map((name) => ({
  383. name,
  384. available: true,
  385. sorted: seq++,
  386. provider: {
  387. id: "azure",
  388. providerName: "Azure",
  389. providerType: "azure",
  390. sorted: 2,
  391. },
  392. })),
  393. ...googleModels.map((name) => ({
  394. name,
  395. available: true,
  396. sorted: seq++,
  397. provider: {
  398. id: "google",
  399. providerName: "Google",
  400. providerType: "google",
  401. sorted: 3,
  402. },
  403. })),
  404. ...anthropicModels.map((name) => ({
  405. name,
  406. available: true,
  407. sorted: seq++,
  408. provider: {
  409. id: "anthropic",
  410. providerName: "Anthropic",
  411. providerType: "anthropic",
  412. sorted: 4,
  413. },
  414. })),
  415. ...baiduModels.map((name) => ({
  416. name,
  417. available: true,
  418. sorted: seq++,
  419. provider: {
  420. id: "baidu",
  421. providerName: "Baidu",
  422. providerType: "baidu",
  423. sorted: 5,
  424. },
  425. })),
  426. ...bytedanceModels.map((name) => ({
  427. name,
  428. available: true,
  429. sorted: seq++,
  430. provider: {
  431. id: "bytedance",
  432. providerName: "ByteDance",
  433. providerType: "bytedance",
  434. sorted: 6,
  435. },
  436. })),
  437. ...alibabaModes.map((name) => ({
  438. name,
  439. available: true,
  440. sorted: seq++,
  441. provider: {
  442. id: "alibaba",
  443. providerName: "Alibaba",
  444. providerType: "alibaba",
  445. sorted: 7,
  446. },
  447. })),
  448. ...tencentModels.map((name) => ({
  449. name,
  450. available: true,
  451. sorted: seq++,
  452. provider: {
  453. id: "tencent",
  454. providerName: "Tencent",
  455. providerType: "tencent",
  456. sorted: 8,
  457. },
  458. })),
  459. ...moonshotModes.map((name) => ({
  460. name,
  461. available: true,
  462. sorted: seq++,
  463. provider: {
  464. id: "moonshot",
  465. providerName: "Moonshot",
  466. providerType: "moonshot",
  467. sorted: 9,
  468. },
  469. })),
  470. ...iflytekModels.map((name) => ({
  471. name,
  472. available: true,
  473. sorted: seq++,
  474. provider: {
  475. id: "iflytek",
  476. providerName: "Iflytek",
  477. providerType: "iflytek",
  478. sorted: 10,
  479. },
  480. })),
  481. ...xAIModes.map((name) => ({
  482. name,
  483. available: true,
  484. sorted: seq++,
  485. provider: {
  486. id: "xai",
  487. providerName: "XAI",
  488. providerType: "xai",
  489. sorted: 11,
  490. },
  491. })),
  492. ...chatglmModels.map((name) => ({
  493. name,
  494. available: true,
  495. sorted: seq++,
  496. provider: {
  497. id: "chatglm",
  498. providerName: "ChatGLM",
  499. providerType: "chatglm",
  500. sorted: 12,
  501. },
  502. })),
  503. ] as const;
  504. export const CHAT_PAGE_SIZE = 15;
  505. export const MAX_RENDER_MSG_COUNT = 45;
  506. // some famous webdav endpoints
  507. export const internalAllowedWebDavEndpoints = [
  508. "https://dav.jianguoyun.com/dav/",
  509. "https://dav.dropdav.com/",
  510. "https://dav.box.com/dav",
  511. "https://nanao.teracloud.jp/dav/",
  512. "https://bora.teracloud.jp/dav/",
  513. "https://webdav.4shared.com/",
  514. "https://dav.idrivesync.com",
  515. "https://webdav.yandex.com",
  516. "https://app.koofr.net/dav/Koofr",
  517. ];
  518. export const DEFAULT_GA_ID = "G-89WN60ZK2E";
  519. export const PLUGINS = [
  520. { name: "Plugins", path: Path.Plugins },
  521. { name: "Stable Diffusion", path: Path.Sd },
  522. { name: "Search Chat", path: Path.SearchChat },
  523. ];
  524. export const SAAS_CHAT_URL = "https://nextchat.dev/chat";
  525. export const SAAS_CHAT_UTM_URL = "https://nextchat.dev/chat?utm=github";