constant.ts 12 KB

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