- 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.
46 lines
1.0 KiB
TypeScript
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 };
|
|
}
|
|
|
|
|
|
|