微软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/

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

相关推荐
程序媛-徐师姐2 分钟前
基于 Python Django 的校园互助平台(附源码,文档)
开发语言·python·django·校园互助·校园互助平台
大数据追光猿26 分钟前
【深度学习】Pytorch项目实战-基于协同过滤实现物品推荐系统
人工智能·pytorch·python·深度学习·ai编程·推荐算法
师范大学生34 分钟前
基于CNN的FashionMNIST数据集识别2——模型训练
python·深度学习·cnn
web1376560764342 分钟前
纯 Python、Django、FastAPI、Flask、Pyramid、Jupyter、dbt 解析和差异分析
python·django·fastapi
大模型铲屎官1 小时前
哈希表入门到精通:从原理到 Python 实现全解析
开发语言·数据结构·python·算法·哈希算法·哈希表
alden_ygq1 小时前
Ollama 模型交互
microsoft·交互
qq4054251971 小时前
基于python的旅客游记和轨迹分析可视化系统设计(新)
开发语言·python
m0_594526302 小时前
基于 PyQt5 实现分组列表滚动吸顶效果
开发语言·python·qt
提拉米苏不吃肉3 小时前
跨平台公式兼容性大模型提示词模板(飞书 + CSDN + Microsoft Word)
microsoft·word·飞书
thinkMoreAndDoMore3 小时前
深度学习(3)-TensorFlow入门(常数张量和变量)
开发语言·人工智能·python