From 84681d3878bf0493806cff0538cbe2b031d5ebfc Mon Sep 17 00:00:00 2001 From: dlb-data <166484772+dlb-data@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:24:03 +0800 Subject: [PATCH 1/3] Update layout.tsx --- app/layout.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/layout.tsx b/app/layout.tsx index 2c89ba4944e..70331e9748e 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -36,6 +36,7 @@ export default function RootLayout({ + From 598468c2b76588c882d4f8f7bf534155217a0c81 Mon Sep 17 00:00:00 2001 From: dlb-data <166484772+dlb-data@users.noreply.github.com> Date: Tue, 9 Apr 2024 16:34:21 +0800 Subject: [PATCH 2/3] Update layout.tsx --- app/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/layout.tsx b/app/layout.tsx index 70331e9748e..5898b21a1fa 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -36,7 +36,7 @@ export default function RootLayout({ - + From 79f342439af8e4c8835c32398b58098acd6bd3dc Mon Sep 17 00:00:00 2001 From: butterfly Date: Tue, 9 Apr 2024 20:49:51 +0800 Subject: [PATCH 3/3] feat: Solve the problem of using openai interface protocol for user-defined claude model & add some famous webdav endpoints --- app/components/exporter.tsx | 3 ++- app/components/home.tsx | 3 ++- app/constant.ts | 12 +++++++++++- app/store/chat.ts | 5 +++-- app/utils/checkers.ts | 21 +++++++++++++++++++++ app/utils/model.ts | 12 ++++++++++-- 6 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 app/utils/checkers.ts diff --git a/app/components/exporter.tsx b/app/components/exporter.tsx index f3f08572154..20e240d93b0 100644 --- a/app/components/exporter.tsx +++ b/app/components/exporter.tsx @@ -40,6 +40,7 @@ import { EXPORT_MESSAGE_CLASS_NAME, ModelProvider } from "../constant"; import { getClientConfig } from "../config/client"; import { ClientApi } from "../client/api"; import { getMessageTextContent } from "../utils"; +import { identifyDefaultClaudeModel } from "../utils/checkers"; const Markdown = dynamic(async () => (await import("./markdown")).Markdown, { loading: () => , @@ -315,7 +316,7 @@ export function PreviewActions(props: { var api: ClientApi; if (config.modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); - } else if (config.modelConfig.model.startsWith("claude")) { + } else if (identifyDefaultClaudeModel(config.modelConfig.model)) { api = new ClientApi(ModelProvider.Claude); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/components/home.tsx b/app/components/home.tsx index 26bb3a44c19..ffac64fdac0 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -29,6 +29,7 @@ import { AuthPage } from "./auth"; import { getClientConfig } from "../config/client"; import { ClientApi } from "../client/api"; import { useAccessStore } from "../store"; +import { identifyDefaultClaudeModel } from "../utils/checkers"; export function Loading(props: { noLogo?: boolean }) { return ( @@ -173,7 +174,7 @@ export function useLoadData() { var api: ClientApi; if (config.modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); - } else if (config.modelConfig.model.startsWith("claude")) { + } else if (identifyDefaultClaudeModel(config.modelConfig.model)) { api = new ClientApi(ModelProvider.Claude); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/constant.ts b/app/constant.ts index ce9b08d1429..1ad76870f45 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -367,4 +367,14 @@ export const DEFAULT_MODELS = [ export const CHAT_PAGE_SIZE = 15; export const MAX_RENDER_MSG_COUNT = 45; -export const internalWhiteWebDavEndpoints = ["https://dav.jianguoyun.com"]; +// some famous webdav endpoints +export const internalWhiteWebDavEndpoints = [ + "https://dav.jianguoyun.com/dav/", + "https://dav.dropdav.com/", + "https://dav.box.com/dav", + "https://nanao.teracloud.jp/dav/", + "https://webdav.4shared.com/", + "https://dav.idrivesync.com", + "https://webdav.yandex.com", + "https://app.koofr.net/dav/Koofr", +]; diff --git a/app/store/chat.ts b/app/store/chat.ts index 53ec11dbf6b..eeddd8463f9 100644 --- a/app/store/chat.ts +++ b/app/store/chat.ts @@ -20,6 +20,7 @@ import { prettyObject } from "../utils/format"; import { estimateTokenLength } from "../utils/token"; import { nanoid } from "nanoid"; import { createPersistStore } from "../utils/store"; +import { identifyDefaultClaudeModel } from "../utils/checkers"; export type ChatMessage = RequestMessage & { date: string; @@ -353,7 +354,7 @@ export const useChatStore = createPersistStore( var api: ClientApi; if (modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); - } else if (modelConfig.model.startsWith("claude")) { + } else if (identifyDefaultClaudeModel(modelConfig.model)) { api = new ClientApi(ModelProvider.Claude); } else { api = new ClientApi(ModelProvider.GPT); @@ -539,7 +540,7 @@ export const useChatStore = createPersistStore( var api: ClientApi; if (modelConfig.model.startsWith("gemini")) { api = new ClientApi(ModelProvider.GeminiPro); - } else if (modelConfig.model.startsWith("claude")) { + } else if (identifyDefaultClaudeModel(modelConfig.model)) { api = new ClientApi(ModelProvider.Claude); } else { api = new ClientApi(ModelProvider.GPT); diff --git a/app/utils/checkers.ts b/app/utils/checkers.ts new file mode 100644 index 00000000000..4496e1039fc --- /dev/null +++ b/app/utils/checkers.ts @@ -0,0 +1,21 @@ +import { useAccessStore } from "../store/access"; +import { useAppConfig } from "../store/config"; +import { collectModels } from "./model"; + +export function identifyDefaultClaudeModel(modelName: string) { + const accessStore = useAccessStore.getState(); + const configStore = useAppConfig.getState(); + + const allModals = collectModels( + configStore.models, + [configStore.customModels, accessStore.customModels].join(","), + ); + + const modelMeta = allModals.find((m) => m.name === modelName); + + return ( + modelName.startsWith("claude") && + modelMeta && + modelMeta.provider?.providerType === "anthropic" + ); +} diff --git a/app/utils/model.ts b/app/utils/model.ts index b2a42ef022a..378fc498e5f 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -22,6 +22,12 @@ export function collectModelTable( }; }); + const customProvider = (modelName: string) => ({ + id: modelName, + providerName: "", + providerType: "custom", + }); + // server custom models customModels .split(",") @@ -34,13 +40,15 @@ export function collectModelTable( // enable or disable all models if (name === "all") { - Object.values(modelTable).forEach((model) => (model.available = available)); + Object.values(modelTable).forEach( + (model) => (model.available = available), + ); } else { modelTable[name] = { name, displayName: displayName || name, available, - provider: modelTable[name]?.provider, // Use optional chaining + provider: modelTable[name]?.provider ?? customProvider(name), // Use optional chaining }; } });