---
title: huanhuan-chat
canonical_url: "https://www.modelscope.cn/models/kmno4zx/huanhuan-chat"
md_url: "https://www.modelscope.cn/models/kmno4zx/huanhuan-chat.md"
repository: kmno4zx/huanhuan-chat
chinese_name: "Chat-嬛嬛"
last_updated: 2023-12-09
license: "Apache License 2.0"
pipeline_tag: text-generation
tasks:
  - text-generation
model_type:
  - qwen
architectures:
  - QWenLMHeadModel
parameters: 1.8B
tensor_type:
  - BF16
library_name:
  - pytorch
  - transformer
  - safetensors
frameworks:
  - Pytorch
inference_backends:
  - "deploy_task text/emb"
  - "lmdeploy 0.9.1"
  - "lmdeploy_turbomind 0.9.1"
  - "sglang 0.5.2"
  - "vllm 0.9.2"
downloads: 1265
stars: 2
---

# huanhuan-chat

> huanhuan-chat - kmno4zx 在 ModelScope 开源的模型。Chat-甄嬛是利用《甄嬛传》剧本中所有关于甄嬛的台词和语句，基于ChatGLM2进行LoRA微调得到的模仿甄嬛语气的聊天语言模型。

kmno4zx/huanhuan-chat 是 ModelScope 魔搭社区上的 1.8B 参数text-generation模型，采用 Apache License 2.0 许可，可用 deploy_task text/emb、lmdeploy 0.9.1、lmdeploy_turbomind 0.9.1 部署。

- **Repository**: kmno4zx/huanhuan-chat
- **License**: Apache License 2.0
- **Tasks**: text-generation
- **Parameters**: 1.8B
- **Inference backends**: deploy_task text/emb, lmdeploy 0.9.1, lmdeploy_turbomind 0.9.1, sglang 0.5.2, vllm 0.9.2
- **Downloads**: 1265
- **Stars**: 2
- **Last updated**: 2023-12-09

Source: https://www.modelscope.cn/models/kmno4zx/huanhuan-chat

---

# Chat-嬛嬛 2.0

**Chat-甄嬛**是利用《甄嬛传》剧本中所有关于甄嬛的台词和语句，基于**ChatGLM2**进行**LoRA微调**得到的模仿甄嬛语气的聊天语言模型。

> 甄嬛，小说《后宫·甄嬛传》和电视剧《甄嬛传》中的女一号，核心女主角。原名甄玉嬛，嫌玉字俗气而改名甄嬛，为汉人甄远道之女，后被雍正赐姓钮祜禄氏，抬旗为满洲上三旗，获名“钮祜禄·甄嬛”。同沈眉庄、安陵容参加选秀，因容貌酷似纯元皇后而被选中。入宫后面对华妃的步步紧逼，沈眉庄被冤、安陵容变心，从偏安一隅的青涩少女变成了能引起血雨腥风的宫斗老手。雍正发现年氏一族的野心后令其父甄远道剪除，甄嬛也于后宫中用她的连环巧计帮皇帝解决政敌，故而深得雍正爱待。几经周折，终于斗垮了嚣张跋扈的华妃。甄嬛封妃时遭皇后宜修暗算，被皇上嫌弃，生下女儿胧月后心灰意冷，自请出宫为尼。然得果郡王爱慕，二人相爱，得知果郡王死讯后立刻设计与雍正再遇，风光回宫。此后甄父冤案平反、甄氏复起，她也生下双生子，在滴血验亲等各种阴谋中躲过宜修的暗害，最后以牺牲自己亲生胎儿的方式扳倒了幕后黑手的皇后。但雍正又逼甄嬛毒杀允礼，以测试甄嬛真心，并让已经生产过孩子的甄嬛去准格尔和亲。甄嬛遂视皇帝为最该毁灭的对象，大结局道尽“人类的一切争斗，皆因统治者的不公不义而起”，并毒杀雍正。四阿哥弘历登基为乾隆，甄嬛被尊为圣母皇太后，权倾朝野，在如懿传中安度晚年。

Chat-甄嬛 2.0，实现了以《甄嬛传》为切入点，打造一套基于小说、剧本的**个性化 AI** 微调大模型完整流程，通过提供任一小说、剧本，指定人物角色，运行本项目完整流程，让每一位用户都基于心仪的小说、剧本打造一个属于自己的、契合角色人设、具备高度智能的个性化 AI。

目前，本项目已实现数据集自动构建、开源模型微调、多维度部署等核心功能模块，支持用户自定义输入语料、指定角色风格，同时基于 ChatGLM、ChatGLM2、BaiChuan 等多种开源大模型，测试效果良好，欢迎大家体验交流~

模型基于Qwen-1.8B-chat模型，使用《甄嬛传》语料做了全量微调。推荐Github仓库：

self-llm：https://github.com/datawhalechina/self-llm.git

huanhuan-chat：https://github.com/KMnO4-zx/huanhuan-chat.git

## 使用方法

```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig

model_dir = 'kmno4zx/huanhuan-chat'
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map={'':0}, torch_dtype=torch.bfloat16, trust_remote_code=True).eval()
# Specify hyperparameters for generation
model.generation_config = GenerationConfig.from_pretrained(model_dir, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参

response, history = model.chat(tokenizer, "朕有一道数学题不会做，怎么办？", history=[], system="现在你要扮演皇帝身边的女人--甄嬛.")
print(response)
```

```te
user:朕有一道数学题不会做，怎么办？
robot:皇上真是文思不敏。
```

![471003c0a7d0c3881a215f5f3d4f45a](images/471003c0a7d0c3881a215f5f3d4f45a.png)
