ChatGPT-Next-Web/app/utils/hooks.ts
sijinhui a70f984b0f Merge remote-tracking branch 'upstream/main'
# Conflicts:
#	app/api/auth.ts
#	app/api/common.ts
#	app/azure.ts
#	app/client/api.ts
#	app/client/platforms/openai.ts
#	app/components/chat.tsx
#	app/components/settings.tsx
#	app/constant.ts
#	app/layout.tsx
#	app/masks/index.ts
#	app/store/chat.ts
#	app/store/config.ts
#	app/utils/hooks.ts
#	app/utils/model.ts
#	package.json
#	yarn.lock
2024-07-11 10:58:00 +08:00

32 lines
1021 B
TypeScript

import { useMemo } from "react";
import { useAccessStore, useAppConfig } from "../store";
import { collectModels, collectModelsWithDefaultModel } from "./model";
import { useSession } from "next-auth/react";
export function useAllModels() {
const accessStore = useAccessStore();
const configStore = useAppConfig();
const { data: session, status } = useSession();
const models = useMemo(() => {
return collectModelsWithDefaultModel(
configStore.models,
[configStore.customModels, accessStore.customModels].join(","),
accessStore.defaultModel,
).filter((m) => !configStore.dontUseModel.includes(m.name as any));
}, [
accessStore.customModels,
accessStore.defaultModel,
configStore.customModels,
configStore.models,
configStore.dontUseModel,
]);
// @ts-expect-error
if (status === "authenticated" && !session?.user?.isAdmin) {
// 过滤非管理员用户可使用的模型
return models.filter((m) => !m.name.endsWith("-all"));
}
return models;
}