jan/web/app/_hooks/useDownloadModel.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

56 lines
1.8 KiB
TypeScript

import { executeSerial } from "@/_services/pluginService";
import { DataService, ModelManagementService } from "@janhq/core";
import { ModelVersion } from "@/_models/ModelVersion";
import { Product } from "@/_models/Product";
import { AssistantModel } from "@/_models/AssistantModel";
export default function useDownloadModel() {
const assistanModel = (
model: Product,
modelVersion: ModelVersion
): AssistantModel => {
return {
_id: modelVersion._id,
name: modelVersion.name,
quantMethod: modelVersion.quantMethod,
bits: modelVersion.bits,
size: modelVersion.size,
maxRamRequired: modelVersion.maxRamRequired,
usecase: modelVersion.usecase,
downloadLink: modelVersion.downloadLink,
startDownloadAt: modelVersion.startDownloadAt,
finishDownloadAt: modelVersion.finishDownloadAt,
productId: model._id,
productName: model.name,
shortDescription: model.shortDescription,
longDescription: model.longDescription,
avatarUrl: model.avatarUrl,
author: model.author,
version: model.version,
modelUrl: model.modelUrl,
nsfw: model.nsfw === true ? false : true,
greeting: model.greeting,
type: model.type,
createdAt: new Date(model.createdAt).getTime(),
updatedAt: new Date(model.updatedAt ?? "").getTime(),
status: "",
releaseDate: -1,
tags: model.tags,
};
};
const downloadModel = async (model: Product, modelVersion: ModelVersion) => {
modelVersion.startDownloadAt = Date.now();
const assistantModel = assistanModel(model, modelVersion);
await executeSerial(ModelManagementService.StoreModel, assistantModel);
await executeSerial(ModelManagementService.DownloadModel, {
downloadUrl: modelVersion.downloadLink,
fileName: modelVersion._id,
});
};
return {
downloadModel,
};
}