jan/web/app/_hooks/useGetMostSuitableModelVersion.ts
Louis b46042654c
chore: update core services and module export (#376)
* chore: update core services and module export

* Correct version of plugins (#374)

Co-authored-by: Hien To <tominhhien97@gmail.com>

* janhq/jan: Update tag build 1.0.2 for data-plugin

* janhq/jan: Update tag build 1.0.2 for inference-plugin

* janhq/jan: Update tag build 1.0.2 for model-management-plugin

* janhq/jan: Update tag build 1.0.2 for monitoring-plugin

* janhq/jan: Update tag build 1.0.2 for openai-plugin

* chore: update web to use @janhq/core module

---------

Co-authored-by: hiento09 <136591877+hiento09@users.noreply.github.com>
Co-authored-by: Hien To <tominhhien97@gmail.com>
Co-authored-by: Service Account <service@jan.ai>
2023-10-17 19:48:43 +07:00

30 lines
1.0 KiB
TypeScript

import { executeSerial } from "@/_services/pluginService";
import { SystemMonitoringService } from "@janhq/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 };
}