constant.ts 14 KB

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