better-chatbot / src /hooks /queries /use-chat-models.ts
Bot
Initial commit for HF Spaces
05c5ed5
Raw
History Blame Contribute Delete
876 Bytes
import { appStore } from "@/app/store";
import { fetcher } from "lib/utils";
import useSWR, { SWRConfiguration } from "swr";
export const useChatModels = (options?: SWRConfiguration) => {
return useSWR<
{
provider: string;
hasAPIKey: boolean;
models: {
name: string;
isToolCallUnsupported: boolean;
isImageInputUnsupported: boolean;
supportedFileMimeTypes: string[];
}[];
}[]
>("/api/chat/models", fetcher, {
dedupingInterval: 60_000 * 5,
revalidateOnFocus: false,
fallbackData: [],
onSuccess: (data) => {
const status = appStore.getState();
if (!status.chatModel) {
const firstProvider = data[0].provider;
const model = data[0].models[0].name;
appStore.setState({ chatModel: { provider: firstProvider, model } });
}
},
...options,
});
};