基于MindNLP和ChatGLM-6B实现一个聊天应用
1.环境配置
pip install -i https://pypi.mirrors.ustc.edu.cn/simple mindspore==2.2.14
# 配置网络线路
pip install mdtex2html
pip install mindnlp
2.镜像模型下载
下载模型,加载模型,测试应用聊天
from mindnlp.transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import gradio as gr
import mdtex2html
model = AutoModelForSeq2SeqLM.from_pretrained('ZhipuAI/ChatGLM-6B', mirror="modelscope").half()
model.set_train(False)
tokenizer = AutoTokenizer.from_pretrained('ZhipuAI/ChatGLM-6B', mirror="modelscope")
prompt = '你好'
history = []
response, _ = model.chat(tokenizer, prompt, history=history, max_length=20)
print(response)