Merge remote-tracking branch 'origin/main' into feat-redesign-ui

This commit is contained in:
butterfly
2024-04-25 11:02:12 +08:00
19 changed files with 720 additions and 334 deletions

View File

@@ -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 || proxyUrl === "/") {
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;
},
};

View File

@@ -1,14 +1,15 @@
import { useMemo } from "react";
import { useAccessStore, useAppConfig } from "../store";
import { collectModels } from "./model";
import { collectModels, collectModelsWithDefaultModel } from "./model";
export function useAllModels() {
const accessStore = useAccessStore();
const configStore = useAppConfig();
const models = useMemo(() => {
return collectModels(
return collectModelsWithDefaultModel(
configStore.models,
[configStore.customModels, accessStore.customModels].join(","),
accessStore.defaultModel,
);
}, [accessStore.customModels, configStore.customModels, configStore.models]);

View File

@@ -1,5 +1,11 @@
import { LLMModel } from "../client/api";
const customProvider = (modelName: string) => ({
id: modelName,
providerName: "",
providerType: "custom",
});
export function collectModelTable(
models: readonly LLMModel[],
customModels: string,
@@ -11,6 +17,7 @@ export function collectModelTable(
name: string;
displayName: string;
provider?: LLMModel["provider"]; // Marked as optional
isDefault?: boolean;
}
> = {};
@@ -22,12 +29,6 @@ export function collectModelTable(
};
});
const customProvider = (modelName: string) => ({
id: modelName,
providerName: "",
providerType: "custom",
});
// server custom models
customModels
.split(",")
@@ -52,6 +53,27 @@ export function collectModelTable(
};
}
});
return modelTable;
}
export function collectModelTableWithDefaultModel(
models: readonly LLMModel[],
customModels: string,
defaultModel: string,
) {
let modelTable = collectModelTable(models, customModels);
if (defaultModel && defaultModel !== "") {
delete modelTable[defaultModel];
modelTable[defaultModel] = {
name: defaultModel,
displayName: defaultModel,
available: true,
provider:
modelTable[defaultModel]?.provider ?? customProvider(defaultModel),
isDefault: true,
};
}
return modelTable;
}
@@ -67,3 +89,17 @@ export function collectModels(
return allModels;
}
export function collectModelsWithDefaultModel(
models: readonly LLMModel[],
customModels: string,
defaultModel: string,
) {
const modelTable = collectModelTableWithDefaultModel(
models,
customModels,
defaultModel,
);
const allModels = Object.values(modelTable);
return allModels;
}