constant.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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. };
  207. export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
  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 DEFAULT_SYSTEM_TEMPLATE = `
  217. You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  218. Knowledge cutoff: {{cutoff}}
  219. Current model: {{model}}
  220. Current time: {{time}}
  221. Latex inline: \\(x^2\\)
  222. Latex block: $$e=mc^2$$
  223. `;
  224. export const SUMMARIZE_MODEL = "gpt-4o-mini";
  225. export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
  226. export const KnowledgeCutOffDate: Record<string, string> = {
  227. default: "2021-09",
  228. "gpt-4-turbo": "2023-12",
  229. "gpt-4-turbo-2024-04-09": "2023-12",
  230. "gpt-4-turbo-preview": "2023-12",
  231. "gpt-4o": "2023-10",
  232. "gpt-4o-2024-05-13": "2023-10",
  233. "gpt-4o-2024-08-06": "2023-10",
  234. "gpt-4o-2024-11-20": "2023-10",
  235. "chatgpt-4o-latest": "2023-10",
  236. "gpt-4o-mini": "2023-10",
  237. "gpt-4o-mini-2024-07-18": "2023-10",
  238. "gpt-4-vision-preview": "2023-04",
  239. "o1-mini": "2023-10",
  240. "o1-preview": "2023-10",
  241. // After improvements,
  242. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
  243. "gemini-pro": "2023-12",
  244. "gemini-pro-vision": "2023-12",
  245. };
  246. export const DEFAULT_TTS_ENGINE = "OpenAI-TTS";
  247. export const DEFAULT_TTS_ENGINES = ["OpenAI-TTS", "Edge-TTS"];
  248. export const DEFAULT_TTS_MODEL = "tts-1";
  249. export const DEFAULT_TTS_VOICE = "alloy";
  250. export const DEFAULT_TTS_MODELS = ["tts-1", "tts-1-hd"];
  251. export const DEFAULT_TTS_VOICES = [
  252. "alloy",
  253. "echo",
  254. "fable",
  255. "onyx",
  256. "nova",
  257. "shimmer",
  258. ];
  259. export const VISION_MODEL_REGEXES = [
  260. /vision/,
  261. /gpt-4o/,
  262. /claude-3/,
  263. /gemini-1\.5/,
  264. /gemini-exp/,
  265. /gemini-2\.0/,
  266. /learnlm/,
  267. /qwen-vl/,
  268. /qwen2-vl/,
  269. /gpt-4-turbo(?!.*preview)/, // Matches "gpt-4-turbo" but not "gpt-4-turbo-preview"
  270. /^dall-e-3$/, // Matches exactly "dall-e-3"
  271. ];
  272. export const EXCLUDE_VISION_MODEL_REGEXES = [/claude-3-5-haiku-20241022/];
  273. const openaiModels = [
  274. "gpt-3.5-turbo",
  275. "gpt-3.5-turbo-1106",
  276. "gpt-3.5-turbo-0125",
  277. "gpt-4",
  278. "gpt-4-0613",
  279. "gpt-4-32k",
  280. "gpt-4-32k-0613",
  281. "gpt-4-turbo",
  282. "gpt-4-turbo-preview",
  283. "gpt-4o",
  284. "gpt-4o-2024-05-13",
  285. "gpt-4o-2024-08-06",
  286. "gpt-4o-2024-11-20",
  287. "chatgpt-4o-latest",
  288. "gpt-4o-mini",
  289. "gpt-4o-mini-2024-07-18",
  290. "gpt-4-vision-preview",
  291. "gpt-4-turbo-2024-04-09",
  292. "gpt-4-1106-preview",
  293. "dall-e-3",
  294. "o1-mini",
  295. "o1-preview",
  296. ];
  297. const googleModels = [
  298. "gemini-1.0-pro", // Deprecated on 2/15/2025
  299. "gemini-1.5-pro-latest",
  300. "gemini-1.5-pro",
  301. "gemini-1.5-pro-002",
  302. "gemini-1.5-pro-exp-0827",
  303. "gemini-1.5-flash-latest",
  304. "gemini-1.5-flash-8b-latest",
  305. "gemini-1.5-flash",
  306. "gemini-1.5-flash-8b",
  307. "gemini-1.5-flash-002",
  308. "gemini-1.5-flash-exp-0827",
  309. "learnlm-1.5-pro-experimental",
  310. "gemini-exp-1114",
  311. "gemini-exp-1121",
  312. "gemini-exp-1206",
  313. "gemini-2.0-flash-exp",
  314. "gemini-2.0-flash-thinking-exp-1219",
  315. ];
  316. const anthropicModels = [
  317. "claude-instant-1.2",
  318. "claude-2.0",
  319. "claude-2.1",
  320. "claude-3-sonnet-20240229",
  321. "claude-3-opus-20240229",
  322. "claude-3-opus-latest",
  323. "claude-3-haiku-20240307",
  324. "claude-3-5-haiku-20241022",
  325. "claude-3-5-haiku-latest",
  326. "claude-3-5-sonnet-20240620",
  327. "claude-3-5-sonnet-20241022",
  328. "claude-3-5-sonnet-latest",
  329. ];
  330. const baiduModels = [
  331. "ernie-4.0-turbo-8k",
  332. "ernie-4.0-8k",
  333. "ernie-4.0-8k-preview",
  334. "ernie-4.0-8k-preview-0518",
  335. "ernie-4.0-8k-latest",
  336. "ernie-3.5-8k",
  337. "ernie-3.5-8k-0205",
  338. "ernie-speed-128k",
  339. "ernie-speed-8k",
  340. "ernie-lite-8k",
  341. "ernie-tiny-8k",
  342. ];
  343. const bytedanceModels = [
  344. "Doubao-lite-4k",
  345. "Doubao-lite-32k",
  346. "Doubao-lite-128k",
  347. "Doubao-pro-4k",
  348. "Doubao-pro-32k",
  349. "Doubao-pro-128k",
  350. ];
  351. const alibabaModes = [
  352. "qwen-turbo",
  353. "qwen-plus",
  354. "qwen-max",
  355. "qwen-max-0428",
  356. "qwen-max-0403",
  357. "qwen-max-0107",
  358. "qwen-max-longcontext",
  359. ];
  360. const tencentModels = [
  361. "hunyuan-pro",
  362. "hunyuan-standard",
  363. "hunyuan-lite",
  364. "hunyuan-role",
  365. "hunyuan-functioncall",
  366. "hunyuan-code",
  367. "hunyuan-vision",
  368. ];
  369. const moonshotModes = ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"];
  370. const iflytekModels = [
  371. "general",
  372. "generalv3",
  373. "pro-128k",
  374. "generalv3.5",
  375. "4.0Ultra",
  376. ];
  377. const deepseekModels = ["deepseek-chat", "deepseek-coder"];
  378. const xAIModes = ["grok-beta"];
  379. const chatglmModels = [
  380. "glm-4-plus",
  381. "glm-4-0520",
  382. "glm-4",
  383. "glm-4-air",
  384. "glm-4-airx",
  385. "glm-4-long",
  386. "glm-4-flashx",
  387. "glm-4-flash",
  388. ];
  389. let seq = 1000; // 内置的模型序号生成器从1000开始
  390. export const DEFAULT_MODELS = [
  391. ...openaiModels.map((name) => ({
  392. name,
  393. available: true,
  394. sorted: seq++, // Global sequence sort(index)
  395. provider: {
  396. id: "openai",
  397. providerName: "OpenAI",
  398. providerType: "openai",
  399. sorted: 1, // 这里是固定的,确保顺序与之前内置的版本一致
  400. },
  401. })),
  402. ...openaiModels.map((name) => ({
  403. name,
  404. available: true,
  405. sorted: seq++,
  406. provider: {
  407. id: "azure",
  408. providerName: "Azure",
  409. providerType: "azure",
  410. sorted: 2,
  411. },
  412. })),
  413. ...googleModels.map((name) => ({
  414. name,
  415. available: true,
  416. sorted: seq++,
  417. provider: {
  418. id: "google",
  419. providerName: "Google",
  420. providerType: "google",
  421. sorted: 3,
  422. },
  423. })),
  424. ...anthropicModels.map((name) => ({
  425. name,
  426. available: true,
  427. sorted: seq++,
  428. provider: {
  429. id: "anthropic",
  430. providerName: "Anthropic",
  431. providerType: "anthropic",
  432. sorted: 4,
  433. },
  434. })),
  435. ...baiduModels.map((name) => ({
  436. name,
  437. available: true,
  438. sorted: seq++,
  439. provider: {
  440. id: "baidu",
  441. providerName: "Baidu",
  442. providerType: "baidu",
  443. sorted: 5,
  444. },
  445. })),
  446. ...bytedanceModels.map((name) => ({
  447. name,
  448. available: true,
  449. sorted: seq++,
  450. provider: {
  451. id: "bytedance",
  452. providerName: "ByteDance",
  453. providerType: "bytedance",
  454. sorted: 6,
  455. },
  456. })),
  457. ...alibabaModes.map((name) => ({
  458. name,
  459. available: true,
  460. sorted: seq++,
  461. provider: {
  462. id: "alibaba",
  463. providerName: "Alibaba",
  464. providerType: "alibaba",
  465. sorted: 7,
  466. },
  467. })),
  468. ...tencentModels.map((name) => ({
  469. name,
  470. available: true,
  471. sorted: seq++,
  472. provider: {
  473. id: "tencent",
  474. providerName: "Tencent",
  475. providerType: "tencent",
  476. sorted: 8,
  477. },
  478. })),
  479. ...moonshotModes.map((name) => ({
  480. name,
  481. available: true,
  482. sorted: seq++,
  483. provider: {
  484. id: "moonshot",
  485. providerName: "Moonshot",
  486. providerType: "moonshot",
  487. sorted: 9,
  488. },
  489. })),
  490. ...iflytekModels.map((name) => ({
  491. name,
  492. available: true,
  493. sorted: seq++,
  494. provider: {
  495. id: "iflytek",
  496. providerName: "Iflytek",
  497. providerType: "iflytek",
  498. sorted: 10,
  499. },
  500. })),
  501. ...xAIModes.map((name) => ({
  502. name,
  503. available: true,
  504. sorted: seq++,
  505. provider: {
  506. id: "xai",
  507. providerName: "XAI",
  508. providerType: "xai",
  509. sorted: 11,
  510. },
  511. })),
  512. ...chatglmModels.map((name) => ({
  513. name,
  514. available: true,
  515. sorted: seq++,
  516. provider: {
  517. id: "chatglm",
  518. providerName: "ChatGLM",
  519. providerType: "chatglm",
  520. sorted: 12,
  521. },
  522. })),
  523. ...deepseekModels.map((name) => ({
  524. name,
  525. available: true,
  526. sorted: seq++,
  527. provider: {
  528. id: "deepseek",
  529. providerName: "DeepSeek",
  530. providerType: "deepseek",
  531. sorted: 13,
  532. },
  533. })),
  534. ] as const;
  535. export const CHAT_PAGE_SIZE = 15;
  536. export const MAX_RENDER_MSG_COUNT = 45;
  537. // some famous webdav endpoints
  538. export const internalAllowedWebDavEndpoints = [
  539. "https://dav.jianguoyun.com/dav/",
  540. "https://dav.dropdav.com/",
  541. "https://dav.box.com/dav",
  542. "https://nanao.teracloud.jp/dav/",
  543. "https://bora.teracloud.jp/dav/",
  544. "https://webdav.4shared.com/",
  545. "https://dav.idrivesync.com",
  546. "https://webdav.yandex.com",
  547. "https://app.koofr.net/dav/Koofr",
  548. ];
  549. export const DEFAULT_GA_ID = "G-89WN60ZK2E";
  550. export const PLUGINS = [
  551. { name: "Plugins", path: Path.Plugins },
  552. { name: "Stable Diffusion", path: Path.Sd },
  553. { name: "Search Chat", path: Path.SearchChat },
  554. ];
  555. export const SAAS_CHAT_URL = "https://nextchat.dev/chat";
  556. export const SAAS_CHAT_UTM_URL = "https://nextchat.dev/chat?utm=github";