微软Autogen框架加载本地llama2

1、实践流程

(1)使用Fastchat框架搭建运行ChatGLM模型openai兼容API

(2)测试AutoGen加载ChatGLM2

2、部署FastChat

2.1、创建虚拟环境

Python version >= 3.8, < 3.12

conda create -n fastchat python=3.10 -y

conda activate fastchat

2.2、下载FastChat

git clone https://github.com/lm-sys/FastChat.git

2.3、依赖框架安装

pip3 install torch==2.0.0+cu117 torchvision==0.15.1+cu117 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu117

pip3 install cpm_kernels -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host=pypi.mirrors.ustc.edu.cn

pip3 install --upgrade pip -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host=pypi.mirrors.ustc.edu.cn

cd FastChat & pip3 install -e ".[model_worker,webui]" -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host=pypi.mirrors.ustc.edu.cn #这行根据自己的设置,或者用别的

2.4、加载模型

需要分别启动控制器、模型执行器和API服务。

controller

cd FastChat

conda activate fastchat

python -m fastchat.serve.controller --host 0.0.0.0


model_worker

cd FastChat

conda activate fastchat

python -m fastchat.serve.model_worker --model-path ./Llama2-chat-Chinese-50W --host 0.0.0.0

上面的Llama2-chat-Chinese-50W 自己的目录,可以用绝对目录

api_server

cd FastChat

conda activate fastchat

python -m fastchat.serve.openai_api_server --host 0.0.0.0 --port 8001

3、Autogen测试

安装Autogen框架:

pip install pyautogen

编写如下代码:

from autogen import oai

from autogen import AssistantAgent, UserProxyAgent, config_list_from_json

def TestAutoGen():

config_list = [

{

"model": "Llama2-chat-Chinese-50W",

"base_url": "http://127.0.0.1:8001/v1",

#"api_type": "open_ai",#该行要注释掉,不然报错

"api_key": "NULL"

}

]

assistant = AssistantAgent("assistant", llm_config={

"config_list": config_list})

user_proxy = UserProxyAgent(

"user_proxy", code_execution_config={"work_dir": "coding"})

user_proxy.initiate_chat(

assistant, message="用react.js写一个用户登录程序")

if name == 'main':

TestAutoGen()

上面的是参照下面的

原文链接:https://blog.csdn.net/weixin_44455388/article/details/135001302

模型下载:https://huggingface.co/RicardoLee/

这个可以直接下载。有好几个模型可以下载。

相关推荐
紫雾凌寒40 分钟前
计算机视觉 |解锁视频理解三剑客——TimeSformer
python·深度学习·神经网络·计算机视觉·transformer·timesformer
Toky丶43 分钟前
【文献阅读】A Survey on Model Compression for Large Language Models
人工智能·语言模型·自然语言处理
_GR44 分钟前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
Francek Chen1 小时前
【大模型科普】AIGC技术发展与应用实践(一文读懂AIGC)
人工智能·深度学习·语言模型·大模型·aigc
程序员杰哥1 小时前
测试用例详解
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
FreakStudio8 小时前
手把手教你用 MicroPython 玩转幻尔串口舵机,代码+教程全公开
python·嵌入式·大学生·面向对象·技术栈·电子diy·电子计算机
tekin8 小时前
基于 Python 开发在线多人游戏服务器案例解析
服务器·python·游戏·在线多人游戏服务器
让学习成为一种生活方式10 小时前
libGL.so.1: cannot open shared object file: No such file or directory-linux022
linux·开发语言·python
java1234_小锋10 小时前
一周学会Flask3 Python Web开发-Jinja2模板继承和include标签使用
python·flask·flask3