85 lines
2.8 KiB
Markdown
Executable File
85 lines
2.8 KiB
Markdown
Executable File
Ubuntu20.04 + python3.11.9 + django
|
||
#1、安装python3.11.9
|
||
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget
|
||
wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz
|
||
tar zxvf Python-3.11.9.tgz
|
||
cd Python-3.11.9
|
||
./configure --enable-optimizations
|
||
make -j$(nproc)
|
||
sudo make altinstall
|
||
python3.11 -m ensurepip --upgrade
|
||
wget https://bootstrap.pypa.io/get-pip.py
|
||
python3.11 get-pip.py
|
||
#2、安装python虚拟环境和依赖
|
||
cd /opt/matagent
|
||
python3.11 -m venv pyautogen
|
||
source pyautogen/bin/activate
|
||
#安装pyautogen
|
||
pip install pyautogen==0.2.34
|
||
pip install flaml[automl]
|
||
pip install chromadb
|
||
pip install Image
|
||
#安装django
|
||
pip install django
|
||
pip install djangorestframework
|
||
pip install requests
|
||
#安装 websocket支持 channels+asgi
|
||
pip install channels
|
||
pip install asgiref # Django Channels 依赖的包
|
||
#运行服务,支持http+websocket websocket接口: ws://192.168.42.130:8000/matagent/chat
|
||
DJANGO_SETTINGS_MODULE=matagent.settings uvicorn matagent.asgi:application --host 0.0.0.0 --port 8000
|
||
#安装nginx
|
||
sudo apt-get update
|
||
sudo apt-get install nginx
|
||
--查看状态
|
||
sudo systemctl status nginx
|
||
--修改配置
|
||
/etc/nginx/default
|
||
nginx配置在default
|
||
|
||
|
||
|
||
|
||
#pip install autogen-agentchat[websockets]~=0.2 fastapi uvicorn
|
||
|
||
|
||
# 完整agent的console版本
|
||
matagent_main.py是入口点。
|
||
安装requirements.txt里面的pyautogen,然后运行即可。
|
||
.coding目录不要删除,里面包含的是一个配置好的,AGENT执行python代码的环境,否则会报错。
|
||
如果存在问题,检查.coding/pyvenv.cfg文件配置
|
||
data目录记录了实验数据,PL和UV数据,不要删除,否则会报错。
|
||
|
||
代码中,agent之间的状态流转逻辑通常为每个group的state_transition函数中,其中return 'auto'表示自动选择合适的agent。
|
||
|
||
# 简单agent的ui版本
|
||
cd ui-simple
|
||
chainlit run --port 8989 appUI.py
|
||
|
||
chainlit继承了pyautogen的AssistantAgent,在这个基础上实现了chainlit的接口。
|
||
class ChainlitAssistantAgent(AssistantAgent):
|
||
class ChainlitUserProxyAgent(UserProxyAgent):
|
||
同时重载了两个方法以发送数据到前端。
|
||
|
||
"""
|
||
Wrapper for AutoGens Assistant Agent
|
||
"""
|
||
def send(
|
||
self,
|
||
message: Union[Dict, str],
|
||
recipient: Agent,
|
||
request_reply: Optional[bool] = None,
|
||
silent: Optional[bool] = False,
|
||
) -> bool:
|
||
cl.run_sync(
|
||
cl.Message(
|
||
content=f'**{self.name}** Sending message to "{recipient.name}":\n\n{message}',
|
||
author=self.name,
|
||
).send()
|
||
)
|
||
super(ChainlitAssistantAgent, self).send(
|
||
message=message,
|
||
recipient=recipient,
|
||
request_reply=request_reply,
|
||
silent=silent,
|
||
) |