constant.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. const openaiModels = [
  252. "gpt-3.5-turbo",
  253. "gpt-3.5-turbo-1106",
  254. "gpt-3.5-turbo-0125",
  255. "gpt-4",
  256. "gpt-4-0613",
  257. "gpt-4-32k",
  258. "gpt-4-32k-0613",
  259. "gpt-4-turbo",
  260. "gpt-4-turbo-preview",
  261. "gpt-4o",
  262. "gpt-4o-2024-05-13",
  263. "gpt-4o-2024-08-06",
  264. "gpt-4o-2024-11-20",
  265. "chatgpt-4o-latest",
  266. "gpt-4o-mini",
  267. "gpt-4o-mini-2024-07-18",
  268. "gpt-4-vision-preview",
  269. "gpt-4-turbo-2024-04-09",
  270. "gpt-4-1106-preview",
  271. "dall-e-3",
  272. "o1-mini",
  273. "o1-preview",
  274. ];
  275. const googleModels = [
  276. "gemini-1.0-pro", // Deprecated on 2/15/2025
  277. "gemini-1.5-pro-latest",
  278. "gemini-1.5-pro",
  279. "gemini-1.5-pro-002",
  280. "gemini-1.5-pro-exp-0827",
  281. "gemini-1.5-flash-latest",
  282. "gemini-1.5-flash-8b-latest",
  283. "gemini-1.5-flash",
  284. "gemini-1.5-flash-8b",
  285. "gemini-1.5-flash-002",
  286. "gemini-1.5-flash-exp-0827",
  287. "learnlm-1.5-pro-experimental",
  288. "gemini-exp-1114",
  289. "gemini-exp-1121",
  290. "gemini-exp-1206",
  291. "gemini-2.0-flash-exp",
  292. "gemini-2.0-flash-thinking-exp-1219",
  293. ];
  294. const anthropicModels = [
  295. "claude-instant-1.2",
  296. "claude-2.0",
  297. "claude-2.1",
  298. "claude-3-sonnet-20240229",
  299. "claude-3-opus-20240229",
  300. "claude-3-opus-latest",
  301. "claude-3-haiku-20240307",
  302. "claude-3-5-haiku-20241022",
  303. "claude-3-5-haiku-latest",
  304. "claude-3-5-sonnet-20240620",
  305. "claude-3-5-sonnet-20241022",
  306. "claude-3-5-sonnet-latest",
  307. ];
  308. const baiduModels = [
  309. "ernie-4.0-turbo-8k",
  310. "ernie-4.0-8k",
  311. "ernie-4.0-8k-preview",
  312. "ernie-4.0-8k-preview-0518",
  313. "ernie-4.0-8k-latest",
  314. "ernie-3.5-8k",
  315. "ernie-3.5-8k-0205",
  316. "ernie-speed-128k",
  317. "ernie-speed-8k",
  318. "ernie-lite-8k",
  319. "ernie-tiny-8k",
  320. ];
  321. const bytedanceModels = [
  322. "Doubao-lite-4k",
  323. "Doubao-lite-32k",
  324. "Doubao-lite-128k",
  325. "Doubao-pro-4k",
  326. "Doubao-pro-32k",
  327. "Doubao-pro-128k",
  328. ];
  329. const alibabaModes = [
  330. "qwen-turbo",
  331. "qwen-plus",
  332. "qwen-max",
  333. "qwen-max-0428",
  334. "qwen-max-0403",
  335. "qwen-max-0107",
  336. "qwen-max-longcontext",
  337. ];
  338. const tencentModels = [
  339. "hunyuan-pro",
  340. "hunyuan-standard",
  341. "hunyuan-lite",
  342. "hunyuan-role",
  343. "hunyuan-functioncall",
  344. "hunyuan-code",
  345. "hunyuan-vision",
  346. ];
  347. const moonshotModes = ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"];
  348. const iflytekModels = [
  349. "general",
  350. "generalv3",
  351. "pro-128k",
  352. "generalv3.5",
  353. "4.0Ultra",
  354. ];
  355. const xAIModes = ["grok-beta"];
  356. const chatglmModels = [
  357. "glm-4-plus",
  358. "glm-4-0520",
  359. "glm-4",
  360. "glm-4-air",
  361. "glm-4-airx",
  362. "glm-4-long",
  363. "glm-4-flashx",
  364. "glm-4-flash",
  365. ];
  366. let seq = 1000; // 内置的模型序号生成器从1000开始
  367. export const DEFAULT_MODELS = [
  368. ...openaiModels.map((name) => ({
  369. name,
  370. available: true,
  371. sorted: seq++, // Global sequence sort(index)
  372. provider: {
  373. id: "openai",
  374. providerName: "OpenAI",
  375. providerType: "openai",
  376. sorted: 1, // 这里是固定的,确保顺序与之前内置的版本一致
  377. },
  378. })),
  379. ...openaiModels.map((name) => ({
  380. name,
  381. available: true,
  382. sorted: seq++,
  383. provider: {
  384. id: "azure",
  385. providerName: "Azure",
  386. providerType: "azure",
  387. sorted: 2,
  388. },
  389. })),
  390. ...googleModels.map((name) => ({
  391. name,
  392. available: true,
  393. sorted: seq++,
  394. provider: {
  395. id: "google",
  396. providerName: "Google",
  397. providerType: "google",
  398. sorted: 3,
  399. },
  400. })),
  401. ...anthropicModels.map((name) => ({
  402. name,
  403. available: true,
  404. sorted: seq++,
  405. provider: {
  406. id: "anthropic",
  407. providerName: "Anthropic",
  408. providerType: "anthropic",
  409. sorted: 4,
  410. },
  411. })),
  412. ...baiduModels.map((name) => ({
  413. name,
  414. available: true,
  415. sorted: seq++,
  416. provider: {
  417. id: "baidu",
  418. providerName: "Baidu",
  419. providerType: "baidu",
  420. sorted: 5,
  421. },
  422. })),
  423. ...bytedanceModels.map((name) => ({
  424. name,
  425. available: true,
  426. sorted: seq++,
  427. provider: {
  428. id: "bytedance",
  429. providerName: "ByteDance",
  430. providerType: "bytedance",
  431. sorted: 6,
  432. },
  433. })),
  434. ...alibabaModes.map((name) => ({
  435. name,
  436. available: true,
  437. sorted: seq++,
  438. provider: {
  439. id: "alibaba",
  440. providerName: "Alibaba",
  441. providerType: "alibaba",
  442. sorted: 7,
  443. },
  444. })),
  445. ...tencentModels.map((name) => ({
  446. name,
  447. available: true,
  448. sorted: seq++,
  449. provider: {
  450. id: "tencent",
  451. providerName: "Tencent",
  452. providerType: "tencent",
  453. sorted: 8,
  454. },
  455. })),
  456. ...moonshotModes.map((name) => ({
  457. name,
  458. available: true,
  459. sorted: seq++,
  460. provider: {
  461. id: "moonshot",
  462. providerName: "Moonshot",
  463. providerType: "moonshot",
  464. sorted: 9,
  465. },
  466. })),
  467. ...iflytekModels.map((name) => ({
  468. name,
  469. available: true,
  470. sorted: seq++,
  471. provider: {
  472. id: "iflytek",
  473. providerName: "Iflytek",
  474. providerType: "iflytek",
  475. sorted: 10,
  476. },
  477. })),
  478. ...xAIModes.map((name) => ({
  479. name,
  480. available: true,
  481. sorted: seq++,
  482. provider: {
  483. id: "xai",
  484. providerName: "XAI",
  485. providerType: "xai",
  486. sorted: 11,
  487. },
  488. })),
  489. ...chatglmModels.map((name) => ({
  490. name,
  491. available: true,
  492. sorted: seq++,
  493. provider: {
  494. id: "chatglm",
  495. providerName: "ChatGLM",
  496. providerType: "chatglm",
  497. sorted: 12,
  498. },
  499. })),
  500. ] as const;
  501. export const CHAT_PAGE_SIZE = 15;
  502. export const MAX_RENDER_MSG_COUNT = 45;
  503. // some famous webdav endpoints
  504. export const internalAllowedWebDavEndpoints = [
  505. "https://dav.jianguoyun.com/dav/",
  506. "https://dav.dropdav.com/",
  507. "https://dav.box.com/dav",
  508. "https://nanao.teracloud.jp/dav/",
  509. "https://bora.teracloud.jp/dav/",
  510. "https://webdav.4shared.com/",
  511. "https://dav.idrivesync.com",
  512. "https://webdav.yandex.com",
  513. "https://app.koofr.net/dav/Koofr",
  514. ];
  515. export const DEFAULT_GA_ID = "G-89WN60ZK2E";
  516. export const PLUGINS = [
  517. { name: "Plugins", path: Path.Plugins },
  518. { name: "Stable Diffusion", path: Path.Sd },
  519. { name: "Search Chat", path: Path.SearchChat },
  520. ];
  521. export const SAAS_CHAT_URL = "https://nextchat.dev/chat";
  522. export const SAAS_CHAT_UTM_URL = "https://nextchat.dev/chat?utm=github";