From fd8d0a1746adc3c337ba9bb9dcefe525d7a19d40 Mon Sep 17 00:00:00 2001 From: butterfly Date: Fri, 12 Apr 2024 14:20:15 +0800 Subject: [PATCH 1/3] feat: fix the logtics of client joining webdav url --- app/utils/cloud/webdav.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/cloud/webdav.ts b/app/utils/cloud/webdav.ts index f7d48dd0393..5b0f3b1238b 100644 --- a/app/utils/cloud/webdav.ts +++ b/app/utils/cloud/webdav.ts @@ -75,7 +75,7 @@ export function createWebDavClient(store: SyncStore) { } let url; - if (proxyUrl.length > 0 || proxyUrl === "/") { + if (proxyUrl.length > 0) { let u = new URL(proxyUrl + "api/webdav/" + path); // add query params u.searchParams.append("endpoint", config.endpoint); From 9564b261d5829d4544676b245ea4c88ef7b4884f Mon Sep 17 00:00:00 2001 From: Algorithm5838 <108630393+Algorithm5838@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:14:14 +0300 Subject: [PATCH 2/3] Update constant.ts --- app/constant.ts | 280 ++++++++---------------------------------------- 1 file changed, 46 insertions(+), 234 deletions(-) diff --git a/app/constant.ts b/app/constant.ts index b90467bb5c2..aaa33bdcf24 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -137,259 +137,71 @@ export const KnowledgeCutOffDate: Record = { "gemini-pro-vision": "2023-12", }; +const openaiModels = [ + "gpt-3.5-turbo", + "gpt-3.5-turbo-0301", + "gpt-3.5-turbo-0613", + "gpt-3.5-turbo-1106", + "gpt-3.5-turbo-0125", + "gpt-3.5-turbo-16k", + "gpt-3.5-turbo-16k-0613", + "gpt-4", + "gpt-4-0314", + "gpt-4-0613", + "gpt-4-1106-preview", + "gpt-4-0125-preview", + "gpt-4-32k", + "gpt-4-32k-0314", + "gpt-4-32k-0613", + "gpt-4-turbo", + "gpt-4-turbo-preview", + "gpt-4-vision-preview", + "gpt-4-turbo-2024-04-09", +]; + +const googleModels = [ + "gemini-1.0-pro", + "gemini-1.5-pro-latest", + "gemini-pro-vision", +]; + +const anthropicModels = [ + "claude-instant-1.2", + "claude-2.0", + "claude-2.1", + "claude-3-sonnet-20240229", + "claude-3-opus-20240229", + "claude-3-haiku-20240307", +]; + export const DEFAULT_MODELS = [ - { - name: "gpt-4", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-0314", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-0613", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-32k", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-32k-0314", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-32k-0613", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-turbo", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-turbo-2024-04-09", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-turbo-preview", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-1106-preview", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-0125-preview", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-4-vision-preview", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo", + ...openaiModels.map((name) => ({ + name, available: true, provider: { id: "openai", providerName: "OpenAI", providerType: "openai", }, - }, - { - name: "gpt-3.5-turbo-0125", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo-0301", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo-0613", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo-1106", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo-16k", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gpt-3.5-turbo-16k-0613", - available: true, - provider: { - id: "openai", - providerName: "OpenAI", - providerType: "openai", - }, - }, - { - name: "gemini-1.0-pro", - available: true, - provider: { - id: "google", - providerName: "Google", - providerType: "google", - }, - }, - { - name: "gemini-1.5-pro-latest", - available: true, - provider: { - id: "google", - providerName: "Google", - providerType: "google", - }, - }, - { - name: "gemini-pro-vision", + })), + ...googleModels.map((name) => ({ + name, available: true, provider: { id: "google", providerName: "Google", providerType: "google", }, - }, - { - name: "claude-instant-1.2", - available: true, - provider: { - id: "anthropic", - providerName: "Anthropic", - providerType: "anthropic", - }, - }, - { - name: "claude-2.0", - available: true, - provider: { - id: "anthropic", - providerName: "Anthropic", - providerType: "anthropic", - }, - }, - { - name: "claude-2.1", - available: true, - provider: { - id: "anthropic", - providerName: "Anthropic", - providerType: "anthropic", - }, - }, - { - name: "claude-3-opus-20240229", - available: true, - provider: { - id: "anthropic", - providerName: "Anthropic", - providerType: "anthropic", - }, - }, - { - name: "claude-3-sonnet-20240229", - available: true, - provider: { - id: "anthropic", - providerName: "Anthropic", - providerType: "anthropic", - }, - }, - { - name: "claude-3-haiku-20240307", + })), + ...anthropicModels.map((name) => ({ + name, available: true, provider: { id: "anthropic", providerName: "Anthropic", providerType: "anthropic", }, - }, + })), ] as const; export const CHAT_PAGE_SIZE = 15; From fb8b8d28da3174e134dc2551f1a97f2fdab27d1d Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 16 Apr 2024 14:50:48 +0800 Subject: [PATCH 3/3] feat: (1) fix issues/4335 and issues/4518 --- app/client/platforms/anthropic.ts | 6 +++++- app/client/platforms/google.ts | 8 +++++++- app/client/platforms/openai.ts | 26 +++++++++++++++----------- app/utils/cloud/webdav.ts | 18 +++++++++--------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/app/client/platforms/anthropic.ts b/app/client/platforms/anthropic.ts index fea3d8654c1..ba07dcc761e 100644 --- a/app/client/platforms/anthropic.ts +++ b/app/client/platforms/anthropic.ts @@ -348,7 +348,11 @@ export class ClaudeApi implements LLMApi { path(path: string): string { const accessStore = useAccessStore.getState(); - let baseUrl: string = accessStore.anthropicUrl; + let baseUrl: string = ""; + + if (accessStore.useCustomConfig) { + baseUrl = accessStore.anthropicUrl; + } // if endpoint is empty, use default endpoint if (baseUrl.trim().length === 0) { diff --git a/app/client/platforms/google.ts b/app/client/platforms/google.ts index 848e5cd3f0d..16fcc7d5177 100644 --- a/app/client/platforms/google.ts +++ b/app/client/platforms/google.ts @@ -104,7 +104,13 @@ export class GeminiProApi implements LLMApi { }; const accessStore = useAccessStore.getState(); - let baseUrl = accessStore.googleUrl; + + let baseUrl = ""; + + if (accessStore.useCustomConfig) { + baseUrl = accessStore.googleUrl; + } + const isApp = !!getClientConfig()?.isApp; let shouldStream = !!options.config.stream; diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 7652ba0f2f9..ca8bc2ebe6f 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -60,15 +60,23 @@ export class ChatGPTApi implements LLMApi { path(path: string): string { const accessStore = useAccessStore.getState(); - const isAzure = accessStore.provider === ServiceProvider.Azure; + let baseUrl = ""; - if (isAzure && !accessStore.isValidAzure()) { - throw Error( - "incomplete azure config, please check it in your settings page", - ); - } + if (accessStore.useCustomConfig) { + const isAzure = accessStore.provider === ServiceProvider.Azure; - let baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl; + if (isAzure && !accessStore.isValidAzure()) { + throw Error( + "incomplete azure config, please check it in your settings page", + ); + } + + if (isAzure) { + path = makeAzurePath(path, accessStore.azureApiVersion); + } + + baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl; + } if (baseUrl.length === 0) { const isApp = !!getClientConfig()?.isApp; @@ -84,10 +92,6 @@ export class ChatGPTApi implements LLMApi { baseUrl = "https://" + baseUrl; } - if (isAzure) { - path = makeAzurePath(path, accessStore.azureApiVersion); - } - console.log("[Proxy Endpoint] ", baseUrl, path); return [baseUrl, path].join("/"); diff --git a/app/utils/cloud/webdav.ts b/app/utils/cloud/webdav.ts index 5b0f3b1238b..0ca781b7584 100644 --- a/app/utils/cloud/webdav.ts +++ b/app/utils/cloud/webdav.ts @@ -63,26 +63,26 @@ export function createWebDavClient(store: SyncStore) { }; }, path(path: string, proxyUrl: string = "") { - // if (!path.endsWith("/")) { - // path += "/"; - // } if (path.startsWith("/")) { path = path.slice(1); } - if (proxyUrl.length > 0 && !proxyUrl.endsWith("/")) { - proxyUrl += "/"; + if (proxyUrl.endsWith("/")) { + proxyUrl = proxyUrl.slice(0, -1); } let url; - if (proxyUrl.length > 0) { - let u = new URL(proxyUrl + "api/webdav/" + path); + const pathPrefix = "/api/webdav/"; + + try { + let u = new URL(proxyUrl + pathPrefix + path); // add query params u.searchParams.append("endpoint", config.endpoint); url = u.toString(); - } else { - url = "/api/upstash/" + path + "?endpoint=" + config.endpoint; + } catch (e) { + url = pathPrefix + path + "?endpoint=" + config.endpoint; } + return url; }, };