constant.ts 12 KB

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