Files
OllaHub/hooks/use-local-models.ts
Evandro Fonseca Junior 8834ef2b4f feat: update dependencies and enhance chat functionality
- Added new Radix UI components including checkbox, label, popover, slider, switch, and tooltip to improve UI interactions.
- Integrated react-syntax-highlighter for better code rendering in chat messages.
- Updated package.json and pnpm-lock.yaml to include new dependencies and ensure compatibility.
- Enhanced chat input to support web search toggling, improving user experience during message composition.
- Implemented auto-saving of chat sessions and improved session management features.
- Refactored chat message rendering to clean up metadata and improve display quality.
2025-11-20 04:26:35 -03:00

46 lines
1.0 KiB
TypeScript

import { useState, useEffect, useCallback } from 'react';
import { invoke } from '@tauri-apps/api/core';
export interface LocalModel {
name: string;
size: string;
id: string;
modified_at: string;
}
export function useLocalModels() {
const [models, setModels] = useState<LocalModel[]>([]);
const [loading, setLoading] = useState(true);
const fetchModels = useCallback(async () => {
setLoading(true);
try {
const list = await invoke<LocalModel[]>('list_local_models');
setModels(list);
} catch (error) {
console.error("Failed to list models:", error);
} finally {
setLoading(false);
}
}, []);
const deleteModel = async (name: string) => {
try {
await invoke('delete_model', { name });
await fetchModels(); // Refresh list
} catch (error) {
console.error("Failed to delete model:", error);
throw error;
}
};
useEffect(() => {
fetchModels();
}, [fetchModels]);
return { models, loading, refresh: fetchModels, deleteModel };
}