Mike0021/MiniCPM5-Pi-Web-Agent
0
1import { env, ModelRegistry, pipeline } from "@huggingface/transformers";2 3const modelId = process.argv[2] || "Mike0021/MiniCPM5-1B-ONNX-Web";4const prompt = process.argv[3] || "Hello";5 6env.allowLocalModels = true;7env.allowRemoteModels = true;8 9const files = await ModelRegistry.get_pipeline_files("text-generation", modelId, {10 dtype: "q4",11 device: "cpu",12});13console.log("files", JSON.stringify(files, null, 2));14 15if (!files.includes("onnx/model_q4.onnx")) {16 throw new Error("Expected onnx/model_q4.onnx in Transformers.js file plan.");17}18 19const generator = await pipeline("text-generation", modelId, {20 dtype: "q4",21 device: "cpu",22});23 24const result = await generator(prompt, {25 max_new_tokens: 2,26 do_sample: false,27 return_full_text: false,28});29 30console.log("generation", JSON.stringify(result, null, 2));31 32 