constant.ts 12 KB

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