赞
踩
一、ChatGLM3介绍
ChatGLM3 是智谱AI和清华大学 KEG 实验室联合发布的新一代对话预训练模型。ChatGLM3-6B 是 ChatGLM3 系列中的开源模型,在保留了前两代模型对话流畅、部署门槛低等众多优秀特性的基础上,ChatGLM3-6B 引入了如下特性:
二、ChatGLM3下载
2.1、下载代码
https://github.com/THUDM/ChatGLM3
2.2、下载模型
- https://modelscope.cn/models/ZhipuAI/chatglm3-6b/summary
-
- git lfs install
- git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
三、修改ChatGLM3的配置
3.1、修改basic_demo下的cli_demo.py
3.2、修改basic_demo下的cli_demo_bad_word_ids.py
3.3、修改basic_demo下的web_demo.py
3.4、修改basic_demo下的web_demo2.py
3.5、修改openai_api_demo下的openai_api.py
四、安装ChatGLM3依赖环境
4.1、根据conda创建python虚拟环境
conda create -n chatglm3 python=3.8
4.2、激活chatglm3
conda activate chatglm3
4.3、进入ChatGLM3代码目录
cd D:\workspace\opensource\openai\ChatGLM3
4.4、安装requirements.txt
pip install protobuf transformers>=4.30.2 cpm_kernels torch>=2.0 gradio mdtex2html sentencepiece accelerate -i https://pypi.douban.com/simple/
pip install -r requirements.txt
五、多种方法启动ChatGLM3
5.1、启动cli_demo.py
python cli_demo.py
演示效果
5.2、启动web_demo.py
- (chatglm3) D:\workspace\opensource\openai\ChatGLM3\basic_demo>python web_demo.py
- Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [00:04<00:00, 1.48it/s]
演示效果
5.3、启动web_demo2.py
- streamlit run web_demo2.py
-
- (chatglm3) D:\workspace\opensource\openai\ChatGLM3\basic_demo>streamlit run web_demo2.py
-
- You can now view your Streamlit app in your browser.
-
- Local URL: http://localhost:8502
- Network URL: http://192.168.1.103:8502
-
- Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [03:56<00:00, 33.82s/it]
演示效果
5.4、启动python openai_api.py
- (chatglm3) D:\workspace\opensource\openai\ChatGLM3\openai_api_demo>python openai_api.py
- Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 7/7 [00:04<00:00, 1.51it/s]
- INFO: Started server process [12124]
- INFO: Waiting for application startup.
- INFO: Application startup complete.
- INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
采用curl测试
curl.exe -X POST -H 'Content-Type: application/json' -i 'http://127.0.0.1:8000/v1/chat/completions' --data '{"model": "chatglm3-6b", "messages": [{"role": "system", "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user'\''s instructions carefully. Respond using markdown."}, {"role": "user", "content": "你好,给我讲一个故事,大概150字"}], "stream": false, "max_tokens": 100, "temperature": 0.8, "top_p": 0.8}'
{"model": "chatglm3-6b", "messages": [{"role": "system", "content": "You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown."}, {"role": "user", "content": "你好,给我讲一个故事,大概150字"}], "stream": false, "max_tokens": 100, "temperature": 0.8, "top_p": 0.8}
采用python openai_api_request.py测试
python openai_api_request.py
- 2023-11-24 16:00:19.558 | DEBUG | __main__:create_chat_completion:144 - ==== request ====
- {'messages': [ChatMessage(role='system', content="You are ChatGLM3, a large language model trained by Zhipu.AI. Follow the user's instructions carefully. Respond using markdown.", name=None, function_call=None), ChatMessage(role='user', content='你好,给我讲一个故事,大概100字', name=None, function_call=None)], 'temperature': 0.8, 'top_p': 0.8, 'max_tokens': 100, 'echo': False, 'stream': False, 'repetition_penalty': 1.1, 'functions': None}
从chatglm2-6b部署来看,chatglm3的部署比之前简单了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。