From a5517a1a51de81f9527f2e734d8412f6f4f8962c Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 5 Feb 2024 12:35:51 +0700 Subject: [PATCH 01/11] Improve Default System Template (#3996) * Feat [UI/UX] [Constant] [DEFAULT System Template] replace hardcoded - [+] feat(constant.ts): replace hardcoded OpenAI with dynamic ServiceProvider variable in DEFAULT_SYSTEM_TEMPLATE * Improve [UI/UX] [Chat] "fillTemplateWith" - [+] feat(chat.ts): add DEFAULT_MODELS to modelConfig - [+] fix(chat.ts): replace replaceAll with regex in output string replacement - [+] refactor(chat.ts): use const instead of let for cutoff variable --- app/constant.ts | 2 +- app/store/chat.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index fc49e3dbc53..68d0e139506 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -95,7 +95,7 @@ export const Google = { export const DEFAULT_INPUT_TEMPLATE = `{{input}}`; // input / time / model / lang export const DEFAULT_SYSTEM_TEMPLATE = ` -You are ChatGPT, a large language model trained by OpenAI. +You are ChatGPT, a large language model trained by {{ServiceProvider}}. Knowledge cutoff: {{cutoff}} Current model: {{model}} Current time: {{time}} diff --git a/app/store/chat.ts b/app/store/chat.ts index dff6b7bf1c6..a3dc940898a 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -6,6 +6,7 @@ import { ModelConfig, ModelType, useAppConfig } from "./config"; import { createEmptyMask, Mask } from "./mask"; import { DEFAULT_INPUT_TEMPLATE, + DEFAULT_MODELS, DEFAULT_SYSTEM_TEMPLATE, KnowledgeCutOffDate, ModelProvider, @@ -91,10 +92,17 @@ function countMessages(msgs: ChatMessage[]) { } function fillTemplateWith(input: string, modelConfig: ModelConfig) { - let cutoff = - KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; + const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; + // Find the model in the DEFAULT_MODELS array that matches the modelConfig.model + const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model); + if (!modelInfo) { + throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`); + } + // Directly use the providerName from the modelInfo + const serviceProvider = modelInfo.provider.providerName; const vars = { + ServiceProvider: serviceProvider, cutoff, model: modelConfig.model, time: new Date().toLocaleString(), @@ -111,7 +119,8 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { } Object.entries(vars).forEach(([name, value]) => { - output = output.replaceAll(`{{${name}}}`, value); + const regex = new RegExp(`{{${name}}}`, 'g'); + output = output.replace(regex, value.toString()); // Ensure value is a string }); return output; From bb26c03141473c9437827ceb559d43041b149604 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Mon, 5 Feb 2024 13:44:46 +0700 Subject: [PATCH 02/11] Feat [UI/UX] [Constants] [Models] gemini-pro KnowledgeCutOffDate (#3997) - [+] feat(constant.ts): add 'gemini-pro' to KnowledgeCutOffDate constant --- app/constant.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/constant.ts b/app/constant.ts index 68d0e139506..f0e895ed9a0 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -111,6 +111,9 @@ export const KnowledgeCutOffDate: Record = { "gpt-4-1106-preview": "2023-04", "gpt-4-0125-preview": "2023-04", "gpt-4-vision-preview": "2023-04", + // After improvements, + // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. + "gemini-pro": "2023-12", }; export const DEFAULT_MODELS = [ From deea4320adbc810e9bb91ac970c63649d59a48e2 Mon Sep 17 00:00:00 2001 From: Shiroki Satsuki Date: Tue, 6 Feb 2024 15:07:01 +0800 Subject: [PATCH 03/11] ci: build universal binary for macos (#3711) * ci: build universal binary for macos * ci: add tauri args * ci: restore rust_target * ci: fallback value for tauri build args * ci: cache yarn --- .github/workflows/app.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index aebba28f7e2..5fc1c911b48 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -43,12 +43,9 @@ jobs: - os: ubuntu-latest arch: x86_64 rust_target: x86_64-unknown-linux-gnu - - os: macos-latest - arch: x86_64 - rust_target: x86_64-apple-darwin - os: macos-latest arch: aarch64 - rust_target: aarch64-apple-darwin + rust_target: x86_64-apple-darwin,aarch64-apple-darwin - os: windows-latest arch: x86_64 rust_target: x86_64-pc-windows-msvc @@ -60,13 +57,14 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 + cache: 'yarn' - name: install Rust stable uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.config.rust_target }} - uses: Swatinem/rust-cache@v2 with: - key: ${{ matrix.config.rust_target }} + key: ${{ matrix.config.os }} - name: install dependencies (ubuntu only) if: matrix.config.os == 'ubuntu-latest' run: | @@ -81,6 +79,7 @@ jobs: TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} with: releaseId: ${{ needs.create-release.outputs.release_id }} + args: ${{ matrix.config.os == 'macos-latest' && '--target universal-apple-darwin' || '' }} publish-release: permissions: From d0463b2089cddbd828639220cb7d0c04cc8b7e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E8=BF=AA?= Date: Tue, 6 Feb 2024 15:11:20 +0800 Subject: [PATCH 04/11] feat(mac): add sign config, fix arm64 build (#4008) Co-authored-by: vir --- .github/workflows/app.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/app.yml b/.github/workflows/app.yml index 5fc1c911b48..7e74cf04595 100644 --- a/.github/workflows/app.yml +++ b/.github/workflows/app.yml @@ -77,6 +77,12 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} + APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }} + APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }} + APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }} + APPLE_ID: ${{ secrets.APPLE_ID }} + APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }} + APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} with: releaseId: ${{ needs.create-release.outputs.release_id }} args: ${{ matrix.config.os == 'macos-latest' && '--target universal-apple-darwin' || '' }} From 887bec019a654aee647aad095b7db0ab34266589 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:34:43 +0800 Subject: [PATCH 05/11] feat: bump version (#4009) --- src-tauri/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 75d6a0d0afa..dac745f928c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "NextChat", - "version": "2.10.1" + "version": "2.10.2" }, "tauri": { "allowlist": { From 462a88ae82cf00242c1bac6ce62a82a50ab1eadc Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Tue, 6 Feb 2024 16:20:12 +0700 Subject: [PATCH 06/11] Fix [CI/CD] [Vercel] Deploy Preview (#4005) - [+] feat(.github/workflows/deploy_preview.yml): add 'reopened' event trigger --- .github/workflows/deploy_preview.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy_preview.yml b/.github/workflows/deploy_preview.yml index 02ee0f1923d..bdbb78c27c5 100644 --- a/.github/workflows/deploy_preview.yml +++ b/.github/workflows/deploy_preview.yml @@ -5,6 +5,7 @@ on: types: - opened - synchronize + - reopened env: VERCEL_TEAM: ${{ secrets.VERCEL_TEAM }} From 9d5801fb5ff21893c6dfc0417ab65eb99ccc0fdc Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:31:49 +0800 Subject: [PATCH 07/11] fix: avoiding not operation for custom models (#4010) --- app/store/chat.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/store/chat.ts b/app/store/chat.ts index a3dc940898a..254325a7552 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -92,14 +92,18 @@ function countMessages(msgs: ChatMessage[]) { } function fillTemplateWith(input: string, modelConfig: ModelConfig) { - const cutoff = KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; + const cutoff = + KnowledgeCutOffDate[modelConfig.model] ?? KnowledgeCutOffDate.default; // Find the model in the DEFAULT_MODELS array that matches the modelConfig.model - const modelInfo = DEFAULT_MODELS.find(m => m.name === modelConfig.model); - if (!modelInfo) { - throw new Error(`Model ${modelConfig.model} not found in DEFAULT_MODELS array.`); + const modelInfo = DEFAULT_MODELS.find((m) => m.name === modelConfig.model); + + var serviceProvider = "OpenAI"; + if (modelInfo) { + // TODO: auto detect the providerName from the modelConfig.model + + // Directly use the providerName from the modelInfo + serviceProvider = modelInfo.provider.providerName; } - // Directly use the providerName from the modelInfo - const serviceProvider = modelInfo.provider.providerName; const vars = { ServiceProvider: serviceProvider, @@ -119,7 +123,7 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) { } Object.entries(vars).forEach(([name, value]) => { - const regex = new RegExp(`{{${name}}}`, 'g'); + const regex = new RegExp(`{{${name}}}`, "g"); output = output.replace(regex, value.toString()); // Ensure value is a string }); From bca74241e636086b633ce39d10804f31437278f3 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:17:11 +0800 Subject: [PATCH 08/11] fix: fix gemini issue when using app (#4013) * chore: update path * fix: fix google auth logic * fix: not using header authorization for google api * chore: revert to allow stream --- app/client/api.ts | 29 ++++++++++++++++------------- app/client/platforms/google.ts | 32 ++++++++++++++++++-------------- app/client/platforms/openai.ts | 7 ++++++- app/components/exporter.tsx | 2 +- app/components/home.tsx | 2 +- app/components/model-config.tsx | 2 +- app/constant.ts | 8 +++++--- app/store/access.ts | 4 +++- app/store/chat.ts | 4 ++-- app/utils/cors.ts | 4 ++-- next.config.mjs | 11 ++++++++++- package.json | 4 ++-- scripts/setup.sh | 2 +- src-tauri/Cargo.lock | 22 +++++++++++----------- src-tauri/Cargo.toml | 26 ++++++++++++++++++++++---- src-tauri/tauri.conf.json | 2 +- 16 files changed, 102 insertions(+), 59 deletions(-) diff --git a/app/client/api.ts b/app/client/api.ts index 56fa3299624..4b39fbfaed2 100644 --- a/app/client/api.ts +++ b/app/client/api.ts @@ -144,10 +144,10 @@ export function getHeaders() { const headers: Record = { "Content-Type": "application/json", "x-requested-with": "XMLHttpRequest", - "Accept": "application/json", + Accept: "application/json", }; const modelConfig = useChatStore.getState().currentSession().mask.modelConfig; - const isGoogle = modelConfig.model === "gemini-pro"; + const isGoogle = modelConfig.model.startsWith("gemini"); const isAzure = accessStore.provider === ServiceProvider.Azure; const authHeader = isAzure ? "api-key" : "Authorization"; const apiKey = isGoogle @@ -155,20 +155,23 @@ export function getHeaders() { : isAzure ? accessStore.azureApiKey : accessStore.openaiApiKey; - + const clientConfig = getClientConfig(); const makeBearer = (s: string) => `${isAzure ? "" : "Bearer "}${s.trim()}`; const validString = (x: string) => x && x.length > 0; - // use user's api key first - if (validString(apiKey)) { - headers[authHeader] = makeBearer(apiKey); - } else if ( - accessStore.enabledAccessControl() && - validString(accessStore.accessCode) - ) { - headers[authHeader] = makeBearer( - ACCESS_CODE_PREFIX + accessStore.accessCode, - ); + // when using google api in app, not set auth header + if (!(isGoogle && clientConfig?.isApp)) { + // use user's api key first + if (validString(apiKey)) { + headers[authHeader] = makeBearer(apiKey); + } else if ( + accessStore.enabledAccessControl() && + validString(accessStore.accessCode) + ) { + headers[authHeader] = makeBearer( + ACCESS_CODE_PREFIX + accessStore.accessCode, + ); + } } return headers; diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index f0f63659f2b..6e335e7fd2f 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -1,15 +1,8 @@ import { Google, REQUEST_TIMEOUT_MS } from "@/app/constant"; import { ChatOptions, getHeaders, LLMApi, LLMModel, LLMUsage } from "../api"; import { useAccessStore, useAppConfig, useChatStore } from "@/app/store"; -import { - EventStreamContentType, - fetchEventSource, -} from "@fortaine/fetch-event-source"; -import { prettyObject } from "@/app/utils/format"; import { getClientConfig } from "@/app/config/client"; -import Locale from "../../locales"; -import { getServerSideConfig } from "@/app/config/server"; -import de from "@/app/locales/de"; +import { DEFAULT_API_HOST } from "@/app/constant"; export class GeminiProApi implements LLMApi { extractMessage(res: any) { console.log("[Response] gemini-pro response: ", res); @@ -21,7 +14,7 @@ export class GeminiProApi implements LLMApi { ); } async chat(options: ChatOptions): Promise { - const apiClient = this; + // const apiClient = this; const messages = options.messages.map((v) => ({ role: v.role.replace("assistant", "model").replace("system", "user"), parts: [{ text: v.content }], @@ -79,20 +72,31 @@ export class GeminiProApi implements LLMApi { ], }; - console.log("[Request] google payload: ", requestPayload); + const isApp = !!getClientConfig()?.isApp; const shouldStream = !!options.config.stream; const controller = new AbortController(); options.onController?.(controller); + const accessStore = useAccessStore.getState(); try { - const chatPath = this.path(Google.ChatPath); + let chatPath = this.path(Google.ChatPath); + + // let baseUrl = accessStore.googleUrl; + + chatPath = isApp + ? DEFAULT_API_HOST + + "/api/proxy/google/" + + Google.ChatPath + + `?key=${accessStore.googleApiKey}` + : chatPath; + const chatPayload = { method: "POST", body: JSON.stringify(requestPayload), signal: controller.signal, headers: getHeaders(), }; - + console.log("[Request] google chatPath: ", chatPath, isApp); // make a fetch request const requestTimeoutId = setTimeout( () => controller.abort(), @@ -134,6 +138,8 @@ export class GeminiProApi implements LLMApi { // start animaion animateResponseText(); + + console.log("[Proxy Endpoint] ", streamChatPath); fetch(streamChatPath, chatPayload) .then((response) => { const reader = response?.body?.getReader(); @@ -187,9 +193,7 @@ export class GeminiProApi implements LLMApi { } else { const res = await fetch(chatPath, chatPayload); clearTimeout(requestTimeoutId); - const resJson = await res.json(); - if (resJson?.promptFeedback?.blockReason) { // being blocked options.onError?.( diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 68a0fda755c..3c3a5180198 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -1,3 +1,4 @@ +"use client"; import { ApiPath, DEFAULT_API_HOST, @@ -45,7 +46,9 @@ export class ChatGPTApi implements LLMApi { if (baseUrl.length === 0) { const isApp = !!getClientConfig()?.isApp; - baseUrl = isApp ? DEFAULT_API_HOST : ApiPath.OpenAI; + baseUrl = isApp + ? DEFAULT_API_HOST + "/proxy" + ApiPath.OpenAI + : ApiPath.OpenAI; } if (baseUrl.endsWith("/")) { @@ -59,6 +62,8 @@ export class ChatGPTApi implements LLMApi { path = makeAzurePath(path, accessStore.azureApiVersion); } + console.log("[Proxy Endpoint] ", baseUrl, path); + return [baseUrl, path].join("/"); } diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index dff17e4abe3..c17ebc8d809 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -307,7 +307,7 @@ export function PreviewActions(props: { setShouldExport(false); var api: ClientApi; - if (config.modelConfig.model === "gemini-pro") { + if (config.modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/components/home.tsx b/app/components/home.tsx index 4be7da0fbda..8386ba144b9 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -171,7 +171,7 @@ export function useLoadData() { const config = useAppConfig(); var api: ClientApi; - if (config.modelConfig.model === "gemini-pro") { + if (config.modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/components/model-config.tsx b/app/components/model-config.tsx index b9f8116747e..e46a018f463 100644 --- a/app/components/model-config.tsx +++ b/app/components/model-config.tsx @@ -92,7 +92,7 @@ export function ModelConfigList(props: { > - {props.modelConfig.model === "gemini-pro" ? null : ( + {props.modelConfig.model.startsWith("gemini") ? null : ( <> = { "gpt-4-1106-preview": "2023-04", "gpt-4-0125-preview": "2023-04", "gpt-4-vision-preview": "2023-04", - // After improvements, + // After improvements, // it's now easier to add "KnowledgeCutOffDate" instead of stupid hardcoding it, as was done previously. "gemini-pro": "2023-12", }; diff --git a/app/store/access.ts b/app/store/access.ts index 9e8024a6aa8..6884e71e3bf 100644 --- a/app/store/access.ts +++ b/app/store/access.ts @@ -12,7 +12,9 @@ import { ensure } from "../utils/clone"; let fetchState = 0; // 0 not fetch, 1 fetching, 2 done const DEFAULT_OPENAI_URL = - getClientConfig()?.buildMode === "export" ? DEFAULT_API_HOST : ApiPath.OpenAI; + getClientConfig()?.buildMode === "export" + ? DEFAULT_API_HOST + "/api/proxy/openai" + : ApiPath.OpenAI; const DEFAULT_ACCESS_STATE = { accessCode: "", diff --git a/app/store/chat.ts b/app/store/chat.ts index 254325a7552..037a6c96050 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -316,7 +316,7 @@ export const useChatStore = createPersistStore( }); var api: ClientApi; - if (modelConfig.model === "gemini-pro") { + if (modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); } else { api = new ClientApi(ModelProvider.GPT); @@ -501,7 +501,7 @@ export const useChatStore = createPersistStore( const modelConfig = session.mask.modelConfig; var api: ClientApi; - if (modelConfig.model === "gemini-pro") { + if (modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/utils/cors.ts b/app/utils/cors.ts index 773f152aafa..20b3e516017 100644 --- a/app/utils/cors.ts +++ b/app/utils/cors.ts @@ -1,8 +1,8 @@ import { getClientConfig } from "../config/client"; -import { ApiPath, DEFAULT_CORS_HOST } from "../constant"; +import { ApiPath, DEFAULT_API_HOST } from "../constant"; export function corsPath(path: string) { - const baseUrl = getClientConfig()?.isApp ? `${DEFAULT_CORS_HOST}` : ""; + const baseUrl = getClientConfig()?.isApp ? `${DEFAULT_API_HOST}` : ""; if (!path.startsWith("/")) { path = "/" + path; diff --git a/next.config.mjs b/next.config.mjs index 4faa63e5450..ae94f489545 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -64,8 +64,17 @@ if (mode !== "export") { nextConfig.rewrites = async () => { const ret = [ + // adjust for previous verison directly using "/api/proxy/" as proxy base route { - source: "/api/proxy/:path*", + source: "/api/proxy/v1/:path*", + destination: "https://api.openai.com/v1/:path*", + }, + { + source: "/api/proxy/google/:path*", + destination: "https://generativelanguage.googleapis.com/:path*", + }, + { + source: "/api/proxy/openai/:path*", destination: "https://api.openai.com/:path*", }, { diff --git a/package.json b/package.json index f28a5a6ecf2..b31d6a901a0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "chatgpt-next-web", + "name": "nextchat", "private": false, "license": "mit", "scripts": { @@ -64,4 +64,4 @@ "resolutions": { "lint-staged/yaml": "^2.2.2" } -} +} \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/setup.sh index 73ed61b1326..50488f963bc 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -54,7 +54,7 @@ if ! command -v node >/dev/null || ! command -v git >/dev/null || ! command -v y fi # Clone the repository and install dependencies -git clone https://github.com/Yidadaa/ChatGPT-Next-Web +git clone https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web cd ChatGPT-Next-Web yarn install diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d93210fc540..eeda9dd8c73 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -431,17 +431,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chatgpt-next-web" -version = "0.1.0" -dependencies = [ - "serde", - "serde_json", - "tauri", - "tauri-build", - "tauri-plugin-window-state", -] - [[package]] name = "chrono" version = "0.4.24" @@ -1824,6 +1813,17 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" +[[package]] +name = "nextchat" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "tauri", + "tauri-build", + "tauri-plugin-window-state", +] + [[package]] name = "nix" version = "0.26.4" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index fee1c860fb9..9c3aef24495 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "chatgpt-next-web" +name = "nextchat" version = "0.1.0" description = "A cross platform app for LLM ChatBot." authors = ["Yidadaa"] license = "mit" repository = "" -default-run = "chatgpt-next-web" +default-run = "nextchat" edition = "2021" rust-version = "1.60" @@ -17,11 +17,29 @@ tauri-build = { version = "1.3.0", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.3.0", features = ["notification-all", "fs-all", "clipboard-all", "dialog-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-icon", "window-set-ignore-cursor-events", "window-set-resizable", "window-show", "window-start-dragging", "window-unmaximize", "window-unminimize"] } +tauri = { version = "1.3.0", features = [ + "notification-all", + "fs-all", + "clipboard-all", + "dialog-all", + "shell-open", + "updater", + "window-close", + "window-hide", + "window-maximize", + "window-minimize", + "window-set-icon", + "window-set-ignore-cursor-events", + "window-set-resizable", + "window-show", + "window-start-dragging", + "window-unmaximize", + "window-unminimize", +] } tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. # If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes. # DO NOT REMOVE!! -custom-protocol = [ "tauri/custom-protocol" ] +custom-protocol = ["tauri/custom-protocol"] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index dac745f928c..86bc92ee185 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -91,7 +91,7 @@ "updater": { "active": true, "endpoints": [ - "https://github.com/Yidadaa/ChatGPT-Next-Web/releases/latest/download/latest.json" + "https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/releases/latest/download/latest.json" ], "dialog": false, "windows": { From 08694556128fa65688e69a77da723b2d986c5063 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:38:02 +0800 Subject: [PATCH 09/11] feat: bump version (#4015) * feat: bump version * feat: bump version --- app/constant.ts | 3 --- src-tauri/tauri.conf.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index 301adca2788..aa38f440792 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -8,9 +8,6 @@ export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/c export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`; export const RUNTIME_CONFIG_DOM = "danger-runtime-config"; -// export const DEFAULT_CORS_HOST = "https://api.nextchat.dev"; -// export const DEFAULT_API_HOST = `${DEFAULT_CORS_HOST}/api/proxy`; - export const DEFAULT_API_HOST = "https://api.nextchat.dev"; export const OPENAI_BASE_URL = "https://api.openai.com"; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 86bc92ee185..9eb256a3812 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -9,7 +9,7 @@ }, "package": { "productName": "NextChat", - "version": "2.10.2" + "version": "2.10.3" }, "tauri": { "allowlist": { From b8f0822214b2f957e55fc6a4b4f404d2685c2735 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:40:30 +0800 Subject: [PATCH 10/11] fix: support custom api endpoint (#4016) --- app/client/platforms/google.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 6e335e7fd2f..aeb91ba7c02 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -72,23 +72,26 @@ export class GeminiProApi implements LLMApi { ], }; + const accessStore = useAccessStore.getState(); + let baseUrl = accessStore.googleUrl; const isApp = !!getClientConfig()?.isApp; - const shouldStream = !!options.config.stream; + let shouldStream = !!options.config.stream; const controller = new AbortController(); options.onController?.(controller); - const accessStore = useAccessStore.getState(); try { let chatPath = this.path(Google.ChatPath); // let baseUrl = accessStore.googleUrl; - chatPath = isApp - ? DEFAULT_API_HOST + - "/api/proxy/google/" + - Google.ChatPath + - `?key=${accessStore.googleApiKey}` - : chatPath; + if (!baseUrl) { + baseUrl = isApp + ? DEFAULT_API_HOST + + "/api/proxy/google/" + + Google.ChatPath + + `?key=${accessStore.googleApiKey}` + : chatPath; + } const chatPayload = { method: "POST", @@ -96,7 +99,7 @@ export class GeminiProApi implements LLMApi { signal: controller.signal, headers: getHeaders(), }; - console.log("[Request] google chatPath: ", chatPath, isApp); + // make a fetch request const requestTimeoutId = setTimeout( () => controller.abort(), @@ -105,10 +108,6 @@ export class GeminiProApi implements LLMApi { if (shouldStream) { let responseText = ""; let remainText = ""; - let streamChatPath = chatPath.replace( - "generateContent", - "streamGenerateContent", - ); let finished = false; let existingTexts: string[] = []; @@ -139,8 +138,10 @@ export class GeminiProApi implements LLMApi { // start animaion animateResponseText(); - console.log("[Proxy Endpoint] ", streamChatPath); - fetch(streamChatPath, chatPayload) + fetch( + baseUrl.replace("generateContent", "streamGenerateContent"), + chatPayload, + ) .then((response) => { const reader = response?.body?.getReader(); const decoder = new TextDecoder(); @@ -191,7 +192,7 @@ export class GeminiProApi implements LLMApi { console.error("Error:", error); }); } else { - const res = await fetch(chatPath, chatPayload); + const res = await fetch(baseUrl, chatPayload); clearTimeout(requestTimeoutId); const resJson = await res.json(); if (resJson?.promptFeedback?.blockReason) { From d74f63655832cca789fc864d06ec96ee741fe225 Mon Sep 17 00:00:00 2001 From: fred-bf <157469842+fred-bf@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:46:52 +0800 Subject: [PATCH 11/11] Fix/gemini app endpoint (#4017) * fix: support custom api endpoint * fix: attach api key to google gemini --- app/client/platforms/google.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index aeb91ba7c02..6832400ca58 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -86,13 +86,13 @@ export class GeminiProApi implements LLMApi { if (!baseUrl) { baseUrl = isApp - ? DEFAULT_API_HOST + - "/api/proxy/google/" + - Google.ChatPath + - `?key=${accessStore.googleApiKey}` + ? DEFAULT_API_HOST + "/api/proxy/google/" + Google.ChatPath : chatPath; } + if (isApp) { + baseUrl += `?key=${accessStore.googleApiKey}`; + } const chatPayload = { method: "POST", body: JSON.stringify(requestPayload),