Spaces:
Running
Running
File size: 1,464 Bytes
79278ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { fetchLLMConfigs, createLLMConfig, updateLLMConfig, setDefaultLLMConfig, deleteLLMConfig } from './llmConfigApi';
export const useLLMConfigs = () => {
const queryClient = useQueryClient();
const { data: configs = [], isLoading, error } = useQuery({
queryKey: ['llmConfigs'],
queryFn: fetchLLMConfigs,
});
const createMutation = useMutation({
mutationFn: createLLMConfig,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['llmConfigs'] });
},
});
const updateMutation = useMutation({
mutationFn: updateLLMConfig,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['llmConfigs'] });
},
});
const setDefaultMutation = useMutation({
mutationFn: setDefaultLLMConfig,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['llmConfigs'] });
},
});
const deleteMutation = useMutation({
mutationFn: deleteLLMConfig,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['llmConfigs'] });
},
});
return {
configs,
isLoading,
error: error ? (error instanceof Error ? error.message : 'Failed to fetch configurations') : null,
createConfig: createMutation.mutateAsync,
updateConfig: updateMutation.mutateAsync,
setAsDefaultConfig: setDefaultMutation.mutateAsync,
deleteConfig: deleteMutation.mutateAsync,
};
}; |