Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 11, 2024
2 parents c24bc21 + 67acc38 commit ae79ff6
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/components/exporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => <LoadingIcon />,
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion app/components/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
];
5 changes: 3 additions & 2 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions app/utils/checkers.ts
Original file line number Diff line number Diff line change
@@ -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"
);
}
12 changes: 10 additions & 2 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export function collectModelTable(
};
});

const customProvider = (modelName: string) => ({
id: modelName,
providerName: "",
providerType: "custom",
});

// server custom models
customModels
.split(",")
Expand All @@ -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
};
}
});
Expand Down

0 comments on commit ae79ff6

Please sign in to comment.