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

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

相关推荐
databook1 分钟前
理论都会,实战就废?7个分析模板,帮你打通任督二脉
python·数据挖掘·数据分析
ZC跨境爬虫1 小时前
极验滑动验证码自动化实战(ddddocr免费方案):本地缺口识别与Playwright滑动模拟
前端·爬虫·python·自动化
单片机学习之路1 小时前
【Python】输入print函数
开发语言·前端·python
后藤十八里1 小时前
极验4消消乐验证码逆向笔记
笔记·爬虫·python
李昊哲小课1 小时前
Python办公自动化教程 - 第1章 openpyxl基础入门 - 第一次用代码操控Excel
开发语言·python·excel·openpyxl
智算菩萨2 小时前
【Python图像处理】4 NumPy数组操作与图像矩阵运算
图像处理·python·numpy
SomeB1oody2 小时前
【Python深度学习】1.1. 多层感知器MLP(人工神经网络)介绍
开发语言·人工智能·python·深度学习·机器学习
数据科学小丫2 小时前
数据分析利器 Pandas :apply() 方法 + map() 配对 + 计算描述统计 + 协方差和相关性 + 异常值处理常用方法(基于 python )
python·数据分析·numpy·pandas
财经资讯数据_灵砚智能2 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年4月6日
大数据·人工智能·python·信息可视化·语言模型·自然语言处理·ai编程
weitingfu2 小时前
Excel VBA 入门到精通(二):变量、数据类型与运算符
java·大数据·开发语言·学习·microsoft·excel·vba