constant.ts 12 KB

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