* @janhq/plugin-core module * refactor web to use exported services from module * refactor data-plugin to provide DAL & move model logics to model management plugin * model-management in TS * add ci auto package, increate version, and publish to npm repository * chore: storage operations * chore: hybrid data-plugin esm & cjs module * chore: PouchDB Driver * chore: documentation --------- Co-authored-by: Hien To <hien@jan.ai> Co-authored-by: Service Account <service@jan.ai>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { executeSerial } from "@/_services/pluginService";
|
|
import { SystemMonitoringService } from "@janhq/plugin-core";
|
|
import { ModelVersion } from "@/_models/ModelVersion";
|
|
import { useState } from "react";
|
|
|
|
export default function useGetMostSuitableModelVersion() {
|
|
const [suitableModel, setSuitableModel] = useState<ModelVersion | undefined>();
|
|
|
|
const getMostSuitableModelVersion = async (modelVersions: ModelVersion[]) => {
|
|
const resourceInfo = await executeSerial(
|
|
SystemMonitoringService.GetResourcesInfo
|
|
);
|
|
const totalRam = resourceInfo.mem.total;
|
|
|
|
// find the model version with the highest required RAM that is still below the user's RAM by 80%
|
|
const modelVersion = modelVersions.reduce((prev, current) => {
|
|
if (current.maxRamRequired > prev.maxRamRequired) {
|
|
if (current.maxRamRequired < totalRam * 0.8) {
|
|
return current;
|
|
}
|
|
}
|
|
return prev;
|
|
});
|
|
|
|
setSuitableModel(modelVersion);
|
|
};
|
|
|
|
return { suitableModel, getMostSuitableModelVersion };
|
|
}
|