constant.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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-mini": "2023-10",
  209. "gpt-4o-mini-2024-07-18": "2023-10",
  210. "gpt-4-vision-preview": "2023-04",
  211. // After improvements,
  212. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
  213. "gemini-pro": "2023-12",
  214. "gemini-pro-vision": "2023-12",
  215. };
  216. const openaiModels = [
  217. "gpt-3.5-turbo",
  218. "gpt-3.5-turbo-1106",
  219. "gpt-3.5-turbo-0125",
  220. "gpt-4",
  221. "gpt-4-0613",
  222. "gpt-4-32k",
  223. "gpt-4-32k-0613",
  224. "gpt-4-turbo",
  225. "gpt-4-turbo-preview",
  226. "gpt-4o",
  227. "gpt-4o-2024-05-13",
  228. "gpt-4o-mini",
  229. "gpt-4o-mini-2024-07-18",
  230. "gpt-4-vision-preview",
  231. "gpt-4-turbo-2024-04-09",
  232. "gpt-4-1106-preview",
  233. "dall-e-3",
  234. ];
  235. const googleModels = [
  236. "gemini-1.0-pro",
  237. "gemini-1.5-pro-latest",
  238. "gemini-1.5-flash-latest",
  239. "gemini-pro-vision",
  240. ];
  241. const anthropicModels = [
  242. "claude-instant-1.2",
  243. "claude-2.0",
  244. "claude-2.1",
  245. "claude-3-sonnet-20240229",
  246. "claude-3-opus-20240229",
  247. "claude-3-haiku-20240307",
  248. "claude-3-5-sonnet-20240620",
  249. ];
  250. const baiduModels = [
  251. "ernie-4.0-turbo-8k",
  252. "ernie-4.0-8k",
  253. "ernie-4.0-8k-preview",
  254. "ernie-4.0-8k-preview-0518",
  255. "ernie-4.0-8k-latest",
  256. "ernie-3.5-8k",
  257. "ernie-3.5-8k-0205",
  258. "ernie-speed-128k",
  259. "ernie-speed-8k",
  260. "ernie-lite-8k",
  261. "ernie-tiny-8k",
  262. ];
  263. const bytedanceModels = [
  264. "Doubao-lite-4k",
  265. "Doubao-lite-32k",
  266. "Doubao-lite-128k",
  267. "Doubao-pro-4k",
  268. "Doubao-pro-32k",
  269. "Doubao-pro-128k",
  270. ];
  271. const alibabaModes = [
  272. "qwen-turbo",
  273. "qwen-plus",
  274. "qwen-max",
  275. "qwen-max-0428",
  276. "qwen-max-0403",
  277. "qwen-max-0107",
  278. "qwen-max-longcontext",
  279. ];
  280. const tencentModels = [
  281. "hunyuan-pro",
  282. "hunyuan-standard",
  283. "hunyuan-lite",
  284. "hunyuan-role",
  285. "hunyuan-functioncall",
  286. "hunyuan-code",
  287. "hunyuan-vision",
  288. ];
  289. const moonshotModes = ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"];
  290. const iflytekModels = [
  291. "general",
  292. "generalv3",
  293. "pro-128k",
  294. "generalv3.5",
  295. "4.0Ultra",
  296. ];
  297. let seq = 1000; // 内置的模型序号生成器从1000开始
  298. export const DEFAULT_MODELS = [
  299. ...openaiModels.map((name) => ({
  300. name,
  301. available: true,
  302. sorted: seq++, // Global sequence sort(index)
  303. provider: {
  304. id: "openai",
  305. providerName: "OpenAI",
  306. providerType: "openai",
  307. sorted: 1, // 这里是固定的,确保顺序与之前内置的版本一致
  308. },
  309. })),
  310. ...openaiModels.map((name) => ({
  311. name,
  312. available: true,
  313. sorted: seq++,
  314. provider: {
  315. id: "azure",
  316. providerName: "Azure",
  317. providerType: "azure",
  318. sorted: 2,
  319. },
  320. })),
  321. ...googleModels.map((name) => ({
  322. name,
  323. available: true,
  324. sorted: seq++,
  325. provider: {
  326. id: "google",
  327. providerName: "Google",
  328. providerType: "google",
  329. sorted: 3,
  330. },
  331. })),
  332. ...anthropicModels.map((name) => ({
  333. name,
  334. available: true,
  335. sorted: seq++,
  336. provider: {
  337. id: "anthropic",
  338. providerName: "Anthropic",
  339. providerType: "anthropic",
  340. sorted: 4,
  341. },
  342. })),
  343. ...baiduModels.map((name) => ({
  344. name,
  345. available: true,
  346. sorted: seq++,
  347. provider: {
  348. id: "baidu",
  349. providerName: "Baidu",
  350. providerType: "baidu",
  351. sorted: 5,
  352. },
  353. })),
  354. ...bytedanceModels.map((name) => ({
  355. name,
  356. available: true,
  357. sorted: seq++,
  358. provider: {
  359. id: "bytedance",
  360. providerName: "ByteDance",
  361. providerType: "bytedance",
  362. sorted: 6,
  363. },
  364. })),
  365. ...alibabaModes.map((name) => ({
  366. name,
  367. available: true,
  368. sorted: seq++,
  369. provider: {
  370. id: "alibaba",
  371. providerName: "Alibaba",
  372. providerType: "alibaba",
  373. sorted: 7,
  374. },
  375. })),
  376. ...tencentModels.map((name) => ({
  377. name,
  378. available: true,
  379. sorted: seq++,
  380. provider: {
  381. id: "tencent",
  382. providerName: "Tencent",
  383. providerType: "tencent",
  384. sorted: 8,
  385. },
  386. })),
  387. ...moonshotModes.map((name) => ({
  388. name,
  389. available: true,
  390. sorted: seq++,
  391. provider: {
  392. id: "moonshot",
  393. providerName: "Moonshot",
  394. providerType: "moonshot",
  395. sorted: 9,
  396. },
  397. })),
  398. ...iflytekModels.map((name) => ({
  399. name,
  400. available: true,
  401. sorted: seq++,
  402. provider: {
  403. id: "iflytek",
  404. providerName: "Iflytek",
  405. providerType: "iflytek",
  406. sorted: 10,
  407. },
  408. })),
  409. ] as const;
  410. export const CHAT_PAGE_SIZE = 15;
  411. export const MAX_RENDER_MSG_COUNT = 45;
  412. // some famous webdav endpoints
  413. export const internalAllowedWebDavEndpoints = [
  414. "https://dav.jianguoyun.com/dav/",
  415. "https://dav.dropdav.com/",
  416. "https://dav.box.com/dav",
  417. "https://nanao.teracloud.jp/dav/",
  418. "https://bora.teracloud.jp/dav/",
  419. "https://webdav.4shared.com/",
  420. "https://dav.idrivesync.com",
  421. "https://webdav.yandex.com",
  422. "https://app.koofr.net/dav/Koofr",
  423. ];
  424. export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }];