constant.ts 15 KB

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