Add ollama support (#7)

This commit is contained in:
Will Chen
2025-04-23 14:48:57 -07:00
committed by GitHub
parent a7b3e66499
commit b616598bab
14 changed files with 386 additions and 73 deletions

View File

@@ -0,0 +1,43 @@
import { useCallback } from "react";
import { useAtom } from "jotai";
import {
localModelsAtom,
localModelsLoadingAtom,
localModelsErrorAtom,
} from "@/atoms/localModelsAtoms";
import { IpcClient } from "@/ipc/ipc_client";
export function useLocalModels() {
const [models, setModels] = useAtom(localModelsAtom);
const [loading, setLoading] = useAtom(localModelsLoadingAtom);
const [error, setError] = useAtom(localModelsErrorAtom);
const ipcClient = IpcClient.getInstance();
/**
* Load local models from Ollama
*/
const loadModels = useCallback(async () => {
setLoading(true);
try {
const modelList = await ipcClient.listLocalModels();
setModels(modelList);
setError(null);
return modelList;
} catch (error) {
console.error("Error loading local models:", error);
setError(error instanceof Error ? error : new Error(String(error)));
return [];
} finally {
setLoading(false);
}
}, [ipcClient, setModels, setError, setLoading]);
return {
models,
loading,
error,
loadModels,
};
}