constant.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. import { stabilityRequestCall } from "@/app/store/sd";
  2. export const OWNER = "Yidadaa";
  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 enum Path {
  21. Home = "/",
  22. Chat = "/chat",
  23. Settings = "/settings",
  24. NewChat = "/new-chat",
  25. Masks = "/masks",
  26. Auth = "/auth",
  27. Sd = "/sd",
  28. SdPanel = "/sd-panel",
  29. }
  30. export enum ApiPath {
  31. Cors = "",
  32. Azure = "/api/azure",
  33. OpenAI = "/api/openai",
  34. Anthropic = "/api/anthropic",
  35. Baidu = "/api/baidu",
  36. ByteDance = "/api/bytedance",
  37. Alibaba = "/api/alibaba",
  38. }
  39. export enum SlotID {
  40. AppBody = "app-body",
  41. CustomModel = "custom-model",
  42. }
  43. export enum FileName {
  44. Masks = "masks.json",
  45. Prompts = "prompts.json",
  46. }
  47. export enum StoreKey {
  48. Chat = "chat-next-web-store",
  49. Access = "access-control",
  50. Config = "app-config",
  51. Mask = "mask-store",
  52. Prompt = "prompt-store",
  53. Update = "chat-update",
  54. Sync = "sync",
  55. SdList = "sd-list",
  56. }
  57. export const DEFAULT_SIDEBAR_WIDTH = 300;
  58. export const MAX_SIDEBAR_WIDTH = 500;
  59. export const MIN_SIDEBAR_WIDTH = 230;
  60. export const NARROW_SIDEBAR_WIDTH = 100;
  61. export const ACCESS_CODE_PREFIX = "nk-";
  62. export const LAST_INPUT_KEY = "last-input";
  63. export const UNFINISHED_INPUT = (id: string) => "unfinished-input-" + id;
  64. export const STORAGE_KEY = "chatgpt-next-web";
  65. export const REQUEST_TIMEOUT_MS = 60000;
  66. export const EXPORT_MESSAGE_CLASS_NAME = "export-markdown";
  67. export enum ServiceProvider {
  68. Stability = "Stability",
  69. OpenAI = "OpenAI",
  70. Azure = "Azure",
  71. Google = "Google",
  72. Anthropic = "Anthropic",
  73. Baidu = "Baidu",
  74. ByteDance = "ByteDance",
  75. Alibaba = "Alibaba",
  76. }
  77. export enum ModelProvider {
  78. Stability = "Stability",
  79. GPT = "GPT",
  80. GeminiPro = "GeminiPro",
  81. Claude = "Claude",
  82. Ernie = "Ernie",
  83. Doubao = "Doubao",
  84. Qwen = "Qwen",
  85. }
  86. export const StabilityPath = {
  87. GeneratePath: "v2beta/stable-image/generate",
  88. };
  89. export const Anthropic = {
  90. ChatPath: "v1/messages",
  91. ChatPath1: "v1/complete",
  92. ExampleEndpoint: "https://api.anthropic.com",
  93. Vision: "2023-06-01",
  94. };
  95. export const OpenaiPath = {
  96. ChatPath: "v1/chat/completions",
  97. UsagePath: "dashboard/billing/usage",
  98. SubsPath: "dashboard/billing/subscription",
  99. ListModelPath: "v1/models",
  100. };
  101. export const Azure = {
  102. ChatPath: (deployName: string, apiVersion: string) =>
  103. `deployments/${deployName}/chat/completions?api-version=${apiVersion}`,
  104. ExampleEndpoint: "https://{resource-url}/openai/deployments/{deploy-id}",
  105. };
  106. export const Google = {
  107. ExampleEndpoint: "https://generativelanguage.googleapis.com/",
  108. ChatPath: (modelName: string) => `v1beta/models/${modelName}:generateContent`,
  109. };
  110. export const Baidu = {
  111. ExampleEndpoint: BAIDU_BASE_URL,
  112. ChatPath: (modelName: string) => {
  113. let endpoint = modelName;
  114. if (modelName === "ernie-4.0-8k") {
  115. endpoint = "completions_pro";
  116. }
  117. if (modelName === "ernie-4.0-8k-preview-0518") {
  118. endpoint = "completions_adv_pro";
  119. }
  120. if (modelName === "ernie-3.5-8k") {
  121. endpoint = "completions";
  122. }
  123. return `rpc/2.0/ai_custom/v1/wenxinworkshop/chat/${endpoint}`;
  124. },
  125. };
  126. export const ByteDance = {
  127. ExampleEndpoint: "https://ark.cn-beijing.volces.com/api/",
  128. ChatPath: "api/v3/chat/completions",
  129. };
  130. export const Alibaba = {
  131. ExampleEndpoint: ALIBABA_BASE_URL,
  132. ChatPath: "v1/services/aigc/text-generation/generation",
  133. };
  134. export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang
  135. // export const DEFAULT_SYSTEM_TEMPLATE = `
  136. // You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  137. // Knowledge cutoff: {{cutoff}}
  138. // Current model: {{model}}
  139. // Current time: {{time}}
  140. // Latex inline: $x^2$
  141. // Latex block: $$e=mc^2$$
  142. // `;
  143. export const DEFAULT_SYSTEM_TEMPLATE = `
  144. You are ChatGPT, a large language model trained by {{ServiceProvider}}.
  145. Knowledge cutoff: {{cutoff}}
  146. Current model: {{model}}
  147. Current time: {{time}}
  148. Latex inline: \\(x^2\\)
  149. Latex block: $$e=mc^2$$
  150. `;
  151. export const SUMMARIZE_MODEL = "gpt-3.5-turbo";
  152. export const GEMINI_SUMMARIZE_MODEL = "gemini-pro";
  153. export const KnowledgeCutOffDate: Record<string, string> = {
  154. default: "2021-09",
  155. "gpt-4-turbo": "2023-12",
  156. "gpt-4-turbo-2024-04-09": "2023-12",
  157. "gpt-4-turbo-preview": "2023-12",
  158. "gpt-4o": "2023-10",
  159. "gpt-4o-2024-05-13": "2023-10",
  160. "gpt-4-vision-preview": "2023-04",
  161. // After improvements,
  162. // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously.
  163. "gemini-pro": "2023-12",
  164. "gemini-pro-vision": "2023-12",
  165. };
  166. const openaiModels = [
  167. "gpt-3.5-turbo",
  168. "gpt-3.5-turbo-1106",
  169. "gpt-3.5-turbo-0125",
  170. "gpt-4",
  171. "gpt-4-0613",
  172. "gpt-4-32k",
  173. "gpt-4-32k-0613",
  174. "gpt-4-turbo",
  175. "gpt-4-turbo-preview",
  176. "gpt-4o",
  177. "gpt-4o-2024-05-13",
  178. "gpt-4-vision-preview",
  179. "gpt-4-turbo-2024-04-09",
  180. "gpt-4-1106-preview",
  181. ];
  182. const googleModels = [
  183. "gemini-1.0-pro",
  184. "gemini-1.5-pro-latest",
  185. "gemini-1.5-flash-latest",
  186. "gemini-pro-vision",
  187. ];
  188. const anthropicModels = [
  189. "claude-instant-1.2",
  190. "claude-2.0",
  191. "claude-2.1",
  192. "claude-3-sonnet-20240229",
  193. "claude-3-opus-20240229",
  194. "claude-3-haiku-20240307",
  195. "claude-3-5-sonnet-20240620",
  196. ];
  197. const baiduModels = [
  198. "ernie-4.0-turbo-8k",
  199. "ernie-4.0-8k",
  200. "ernie-4.0-8k-preview",
  201. "ernie-4.0-8k-preview-0518",
  202. "ernie-4.0-8k-latest",
  203. "ernie-3.5-8k",
  204. "ernie-3.5-8k-0205",
  205. ];
  206. const bytedanceModels = [
  207. "Doubao-lite-4k",
  208. "Doubao-lite-32k",
  209. "Doubao-lite-128k",
  210. "Doubao-pro-4k",
  211. "Doubao-pro-32k",
  212. "Doubao-pro-128k",
  213. ];
  214. const alibabaModes = [
  215. "qwen-turbo",
  216. "qwen-plus",
  217. "qwen-max",
  218. "qwen-max-0428",
  219. "qwen-max-0403",
  220. "qwen-max-0107",
  221. "qwen-max-longcontext",
  222. ];
  223. export const DEFAULT_MODELS = [
  224. ...openaiModels.map((name) => ({
  225. name,
  226. available: true,
  227. provider: {
  228. id: "openai",
  229. providerName: "OpenAI",
  230. providerType: "openai",
  231. },
  232. })),
  233. ...openaiModels.map((name) => ({
  234. name,
  235. available: true,
  236. provider: {
  237. id: "azure",
  238. providerName: "Azure",
  239. providerType: "azure",
  240. },
  241. })),
  242. ...googleModels.map((name) => ({
  243. name,
  244. available: true,
  245. provider: {
  246. id: "google",
  247. providerName: "Google",
  248. providerType: "google",
  249. },
  250. })),
  251. ...anthropicModels.map((name) => ({
  252. name,
  253. available: true,
  254. provider: {
  255. id: "anthropic",
  256. providerName: "Anthropic",
  257. providerType: "anthropic",
  258. },
  259. })),
  260. ...baiduModels.map((name) => ({
  261. name,
  262. available: true,
  263. provider: {
  264. id: "baidu",
  265. providerName: "Baidu",
  266. providerType: "baidu",
  267. },
  268. })),
  269. ...bytedanceModels.map((name) => ({
  270. name,
  271. available: true,
  272. provider: {
  273. id: "bytedance",
  274. providerName: "ByteDance",
  275. providerType: "bytedance",
  276. },
  277. })),
  278. ...alibabaModes.map((name) => ({
  279. name,
  280. available: true,
  281. provider: {
  282. id: "alibaba",
  283. providerName: "Alibaba",
  284. providerType: "alibaba",
  285. },
  286. })),
  287. ] as const;
  288. export const CHAT_PAGE_SIZE = 15;
  289. export const MAX_RENDER_MSG_COUNT = 45;
  290. // some famous webdav endpoints
  291. export const internalAllowedWebDavEndpoints = [
  292. "https://dav.jianguoyun.com/dav/",
  293. "https://dav.dropdav.com/",
  294. "https://dav.box.com/dav",
  295. "https://nanao.teracloud.jp/dav/",
  296. "https://bora.teracloud.jp/dav/",
  297. "https://webdav.4shared.com/",
  298. "https://dav.idrivesync.com",
  299. "https://webdav.yandex.com",
  300. "https://app.koofr.net/dav/Koofr",
  301. ];
  302. export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }];