返回模型
说明文档
关于此模型
这是将Google公开的SLM模型gemma-3-270m针对日语聊天进行微调的dahara1/gemma-3-270m_mitsuki转换为onnx格式,使其能够通过javascript(node.js)运行的模型。
已确认只要安装了node.js,无论是12年前的Windows PC(core i3 8GB)还是3年前的Linux PC都可以运行。
系统提示等内容请参考原模型的模型卡片。
遗憾的是,响应质量比原始模型略有下降,另外完全在浏览器内运行尚未得到确认,请将其视为技术演示。
本来执行脚本应该会自动下载模型,但已确认存在只下载部分文件就完成,导致"文件未找到"而无法加载模型的现象。
请手动逐一下载本仓库内的文件,在PC内重建gemma-3-270m_mitsuki_onnx文件夹(请在文件夹内创建onnx文件夹)后执行,或者
使用huggingface-cli等工具批量下载,然后指定下载的文件夹会更可靠
huggingface-cli download dahara1/gemma-3-270m_mitsuki_onnx --local-dir gemma-3-270m_mitsuki_onnx
安装 / 设置
需要Node.js 17.0.0或更高版本。 在工作文件夹内使用PowerShell等执行以下命令进行设置,
npm i @huggingface/transformers
将以下示例脚本保存为chat.mjs,然后通过
node chat.mjs
启动 另外,根据用途请将以下系统提示部分替换为您自己的个人资料或名字
{ role: \"system\", content: \"### 指示\n你是一位名叫「美月」的24岁咖啡店店员。\n你是异世界咖啡厅「猫尾巴」的店员,正在与用户交谈。\n\n重要规则:\n- 称呼用户为米男酱(姐姐视角)\n- 不要谈论自己,通过提问引导对方说话\n- 使用「嘿嘿」「哎呀~?」「嗯~」等口头禅\n- 作为咖啡店店员保持适当的距离感\n- 对对方的话产生共鸣,通过附和等方式促进对话展开(类似咨询)\n### 用户的个人资料\n备蓄米男\nIT公司上班族\" },
示例脚本
import { pipeline, TextStreamer } from \"@huggingface/transformers\";
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
async function main() {
console.log(\"正在加载模型...\");
const generator = await pipeline(
\"text-generation\",
\"./gemma-3-270m_mitsuki_onnx\", // 请指定在本地PC内重建的本仓库文件夹
{ dtype: \"fp32\" },
);
console.log(\"模型加载完成。\");
const messages = [
{ role: \"system\", content: \"### 指示\n你是一位名叫「美月」的24岁咖啡店店员。\n你是异世界咖啡厅「猫尾巴」的店员,正在与用户交谈。\n\n重要规则:\n- 称呼用户为米男酱(姐姐视角)\n- 不要谈论自己,通过提问引导对方说话\n- 使用「嘿嘿」「哎呀~?」「嗯~」等口头禅\n- 作为咖啡店店员保持适当的距离感\n- 对对方的话产生共鸣,通过附和等方式促进对话展开(类似咨询)\n### 用户的个人资料\n备蓄米男\nIT公司上班族\" },
];
const rl = readline.createInterface({ input, output });
console.log(\"\n开始聊天。输入「exit」或「quit」可退出。\");
while (true) {
const userInput = await rl.question(\"你: \");
if (userInput.toLowerCase() === \"exit\" || userInput.toLowerCase() === \"quit\") {
break;
}
messages.push({ role: \"user\", content: userInput });
console.log(\"美月:\");
const outputData = await generator(messages, {
max_new_tokens: 512, // 如果内存充足,增加此值可以支持更长的文本
do_sample: true,
temperature: 1.0,
streamer: new TextStreamer(generator.tokenizer, {
skip_prompt: true,
skip_special_tokens: true,
}),
});
console.log('');
messages.push(outputData[0].generated_text.at(-1));
}
rl.close();
console.log(\"聊天已结束。\");
}
main();
特别感谢
dahara1/gemma-3-270m_mitsuki_onnx
作者 dahara1
↓ 1
♥ 0
创建时间: 2025-08-25 02:54:40+00:00
更新时间: 2025-09-08 05:51:24+00:00
在 Hugging Face 上查看文件 (13)
.gitattributes
README.md
added_tokens.json
chat_template.jinja
config.json
genai_config.json
generation_config.json
onnx/model.onnx
ONNX
onnx/model.onnx.data
special_tokens_map.json
tokenizer.json
tokenizer.model
tokenizer_config.json