constant.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. 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. SpeechPath: "v1/audio/speech",
  129. TranscriptionPath: "v1/audio/transcriptions",
  130. ImagePath: "v1/images/generations",
  131. UsagePath: "dashboard/billing/usage",
  132. SubsPath: "dashboard/billing/subscription",
  133. ListModelPath: "v1/models",
  134. };
  135. export const Azure = {
  136. ChatPath: (deployName: string, apiVersion: string) =>
  137. `deployments/${deployName}/chat/completions?api-version=${apiVersion}`,
  138. // https://<your_resource_name>.openai.azure.com/openai/deployments/<your_deployment_name>/images/generations?api-version=<api_version>
  139. ImagePath: (deployName: string, apiVersion: string) =>
  140. `deployments/${deployName}/images/generations?api-version=${apiVersion}`,
  141. ExampleEndpoint: "https://{resource-url}/openai",
  142. };
  143. export const Google = {
  144. ExampleEndpoint: "https://generativelanguage.googleapis.com/",
  145. ChatPath: (modelName: string) =>
  146. `v1beta/models/${modelName}:streamGenerateContent`,
  147. };
  148. export const Baidu = {
  149. ExampleEndpoint: BAIDU_BASE_URL,
  150. ChatPath: (modelName: string) => {
  151. let endpoint = modelName;
  152. if (modelName === "ernie-4.0-8k") {
  153. endpoint = "completions_pro";
  154. }
  155. if (modelName === "ernie-4.0-8k-preview-0518") {
  156. endpoint = "completions_adv_pro";
  157. }
  158. if (modelName === "ernie-3.5-8k") {
  159. endpoint = "completions";
  160. }
  161. if (modelName === "ernie-speed-8k") {
  162. endpoint = "ernie_speed";
  163. }
  164. return `rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${endpoint}`;
  165. },
  166. };
  167. export const ByteDance = {
  168. ExampleEndpoint: "https://ark.cn-beijing.volces.com/api/",
  169. ChatPath: "api/v3/chat/completions",
  170. };
  171. export const Alibaba = {
  172. ExampleEndpoint: ALIBABA_BASE_URL,
  173. ChatPath: "v1/services/aigc/text-generation/generation",
  174. };
  175. export const Tencent = {
  176. ExampleEndpoint: TENCENT_BASE_URL,
  177. };
  178. export const Moonshot = {
  179. ExampleEndpoint: MOONSHOT_BASE_URL,
  180. ChatPath: "v1/chat/completions",
  181. };
  182. export const Iflytek = {
  183. ExampleEndpoint: IFLYTEK_BASE_URL,
  184. ChatPath: "v1/chat/completions",
  185. };
  186. export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
  187. // export const DEFAULT_SYSTEM_TEMPLATE = `
  188. // You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  189. // Knowledge cutoff: {{cutoff}}
  190. // Current model: {{model}}
  191. // Current time: {{time}}
  192. // Latex inline: $x^2$
  193. // Latex block: $$e=mc^2$$
  194. // `;
  195. export const DEFAULT_SYSTEM_TEMPLATE = `
  196. You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  197. Knowledge cutoff: {{cutoff}}
  198. Current model: {{model}}
  199. Current time: {{time}}
  200. Latex inline: \\(x^2\\)
  201. Latex block: $$e=mc^2$$
  202. `;
  203. export const SUMMARIZE_MODEL = "gpt-4o-mini";
  204. export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
  205. export const KnowledgeCutOffDate: Record<string, string> = {
  206. default: "2021-09",
  207. "gpt-4-turbo": "2023-12",
  208. "gpt-4-turbo-2024-04-09": "2023-12",
  209. "gpt-4-turbo-preview": "2023-12",
  210. "gpt-4o": "2023-10",
  211. "gpt-4o-2024-05-13": "2023-10",
  212. "gpt-4o-2024-08-06": "2023-10",
  213. "gpt-4o-mini": "2023-10",
  214. "gpt-4o-mini-2024-07-18": "2023-10",
  215. "gpt-4-vision-preview": "2023-04",
  216. // After improvements,
  217. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
  218. "gemini-pro": "2023-12",
  219. "gemini-pro-vision": "2023-12",
  220. };
  221. export const DEFAULT_TTS_ENGINE = "OpenAI-TTS";
  222. export const DEFAULT_TTS_ENGINES = ["OpenAI-TTS", "Edge-TTS"];
  223. export const DEFAULT_TTS_MODEL = "tts-1";
  224. export const DEFAULT_TTS_VOICE = "alloy";
  225. export const DEFAULT_TTS_MODELS = ["tts-1", "tts-1-hd"];
  226. export const DEFAULT_TTS_VOICES = [
  227. "alloy",
  228. "echo",
  229. "fable",
  230. "onyx",
  231. "nova",
  232. "shimmer",
  233. ];
  234. export const DEFAULT_STT_ENGINE = "WebAPI";
  235. export const DEFAULT_STT_ENGINES = ["WebAPI", "OpenAI Whisper"];
  236. export const FIREFOX_DEFAULT_STT_ENGINE = "OpenAI Whisper";
  237. const openaiModels = [
  238. "gpt-3.5-turbo",
  239. "gpt-3.5-turbo-1106",
  240. "gpt-3.5-turbo-0125",
  241. "gpt-4",
  242. "gpt-4-0613",
  243. "gpt-4-32k",
  244. "gpt-4-32k-0613",
  245. "gpt-4-turbo",
  246. "gpt-4-turbo-preview",
  247. "gpt-4o",
  248. "gpt-4o-2024-05-13",
  249. "gpt-4o-2024-08-06",
  250. "gpt-4o-mini",
  251. "gpt-4o-mini-2024-07-18",
  252. "gpt-4-vision-preview",
  253. "gpt-4-turbo-2024-04-09",
  254. "gpt-4-1106-preview",
  255. "dall-e-3",
  256. ];
  257. const googleModels = [
  258. "gemini-1.0-pro",
  259. "gemini-1.5-pro-latest",
  260. "gemini-1.5-flash-latest",
  261. "gemini-pro-vision",
  262. ];
  263. const anthropicModels = [
  264. "claude-instant-1.2",
  265. "claude-2.0",
  266. "claude-2.1",
  267. "claude-3-sonnet-20240229",
  268. "claude-3-opus-20240229",
  269. "claude-3-haiku-20240307",
  270. "claude-3-5-sonnet-20240620",
  271. ];
  272. const baiduModels = [
  273. "ernie-4.0-turbo-8k",
  274. "ernie-4.0-8k",
  275. "ernie-4.0-8k-preview",
  276. "ernie-4.0-8k-preview-0518",
  277. "ernie-4.0-8k-latest",
  278. "ernie-3.5-8k",
  279. "ernie-3.5-8k-0205",
  280. "ernie-speed-128k",
  281. "ernie-speed-8k",
  282. "ernie-lite-8k",
  283. "ernie-tiny-8k",
  284. ];
  285. const bytedanceModels = [
  286. "Doubao-lite-4k",
  287. "Doubao-lite-32k",
  288. "Doubao-lite-128k",
  289. "Doubao-pro-4k",
  290. "Doubao-pro-32k",
  291. "Doubao-pro-128k",
  292. ];
  293. const alibabaModes = [
  294. "qwen-turbo",
  295. "qwen-plus",
  296. "qwen-max",
  297. "qwen-max-0428",
  298. "qwen-max-0403",
  299. "qwen-max-0107",
  300. "qwen-max-longcontext",
  301. ];
  302. const tencentModels = [
  303. "hunyuan-pro",
  304. "hunyuan-standard",
  305. "hunyuan-lite",
  306. "hunyuan-role",
  307. "hunyuan-functioncall",
  308. "hunyuan-code",
  309. "hunyuan-vision",
  310. ];
  311. const moonshotModes = ["moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k"];
  312. const iflytekModels = [
  313. "general",
  314. "generalv3",
  315. "pro-128k",
  316. "generalv3.5",
  317. "4.0Ultra",
  318. ];
  319. let seq = 1000; // 内置的模型序号生成器从1000开始
  320. export const DEFAULT_MODELS = [
  321. ...openaiModels.map((name) => ({
  322. name,
  323. available: true,
  324. sorted: seq++, // Global sequence sort(index)
  325. provider: {
  326. id: "openai",
  327. providerName: "OpenAI",
  328. providerType: "openai",
  329. sorted: 1, // 这里是固定的,确保顺序与之前内置的版本一致
  330. },
  331. })),
  332. ...openaiModels.map((name) => ({
  333. name,
  334. available: true,
  335. sorted: seq++,
  336. provider: {
  337. id: "azure",
  338. providerName: "Azure",
  339. providerType: "azure",
  340. sorted: 2,
  341. },
  342. })),
  343. ...googleModels.map((name) => ({
  344. name,
  345. available: true,
  346. sorted: seq++,
  347. provider: {
  348. id: "google",
  349. providerName: "Google",
  350. providerType: "google",
  351. sorted: 3,
  352. },
  353. })),
  354. ...anthropicModels.map((name) => ({
  355. name,
  356. available: true,
  357. sorted: seq++,
  358. provider: {
  359. id: "anthropic",
  360. providerName: "Anthropic",
  361. providerType: "anthropic",
  362. sorted: 4,
  363. },
  364. })),
  365. ...baiduModels.map((name) => ({
  366. name,
  367. available: true,
  368. sorted: seq++,
  369. provider: {
  370. id: "baidu",
  371. providerName: "Baidu",
  372. providerType: "baidu",
  373. sorted: 5,
  374. },
  375. })),
  376. ...bytedanceModels.map((name) => ({
  377. name,
  378. available: true,
  379. sorted: seq++,
  380. provider: {
  381. id: "bytedance",
  382. providerName: "ByteDance",
  383. providerType: "bytedance",
  384. sorted: 6,
  385. },
  386. })),
  387. ...alibabaModes.map((name) => ({
  388. name,
  389. available: true,
  390. sorted: seq++,
  391. provider: {
  392. id: "alibaba",
  393. providerName: "Alibaba",
  394. providerType: "alibaba",
  395. sorted: 7,
  396. },
  397. })),
  398. ...tencentModels.map((name) => ({
  399. name,
  400. available: true,
  401. sorted: seq++,
  402. provider: {
  403. id: "tencent",
  404. providerName: "Tencent",
  405. providerType: "tencent",
  406. sorted: 8,
  407. },
  408. })),
  409. ...moonshotModes.map((name) => ({
  410. name,
  411. available: true,
  412. sorted: seq++,
  413. provider: {
  414. id: "moonshot",
  415. providerName: "Moonshot",
  416. providerType: "moonshot",
  417. sorted: 9,
  418. },
  419. })),
  420. ...iflytekModels.map((name) => ({
  421. name,
  422. available: true,
  423. sorted: seq++,
  424. provider: {
  425. id: "iflytek",
  426. providerName: "Iflytek",
  427. providerType: "iflytek",
  428. sorted: 10,
  429. },
  430. })),
  431. ] as const;
  432. export const CHAT_PAGE_SIZE = 15;
  433. export const MAX_RENDER_MSG_COUNT = 45;
  434. // some famous webdav endpoints
  435. export const internalAllowedWebDavEndpoints = [
  436. "https://dav.jianguoyun.com/dav/",
  437. "https://dav.dropdav.com/",
  438. "https://dav.box.com/dav",
  439. "https://nanao.teracloud.jp/dav/",
  440. "https://bora.teracloud.jp/dav/",
  441. "https://webdav.4shared.com/",
  442. "https://dav.idrivesync.com",
  443. "https://webdav.yandex.com",
  444. "https://app.koofr.net/dav/Koofr",
  445. ];
  446. export const DEFAULT_GA_ID = "G-89WN60ZK2E";
  447. export const PLUGINS = [
  448. { name: "Stable Diffusion", path: Path.Sd },
  449. { name: "Search Chat", path: Path.SearchChat },
  450. ];