mirror of
https://github.com/xszyou/Fay.git
synced 2026-08-30 17:33:39 +08:00
紧急修复
1、修复mcp工具获取于调用的线程同步问题; 2、修复因记忆反思而导致的记忆混乱,无法多伦对话问题; 3、更换镜像服务商。
This commit is contained in:
@@ -57,7 +57,18 @@
|
||||
|
||||
### **环境**
|
||||
- Python 3.12
|
||||
- Windows、macos、linux
|
||||
|
||||
- Windows、macos、ubuntu
|
||||
|
||||
- 注:ubuntu需要先安装gcc及portaudio
|
||||
|
||||
- ````bash
|
||||
sudo apt update
|
||||
sudo apt install build-essential
|
||||
sudo apt install portaudio19-dev
|
||||
````
|
||||
|
||||
|
||||
|
||||
### **安装依赖**
|
||||
|
||||
@@ -76,22 +87,9 @@ python main.py
|
||||
|
||||
|
||||
|
||||
## **或docker 启动**
|
||||
|
||||
1. 下载助理版
|
||||
https://github.com/xszyou/Fay
|
||||
2. 修改 `./system.conf` 文件
|
||||
3. 删除requirements.txt下pyqt5~=5.15.6
|
||||
|
||||
build (修改配置文件后,需要重新build)
|
||||
```shell
|
||||
docker build -t fay ./fay-assistant-edition
|
||||
```
|
||||
run
|
||||
```shell
|
||||
docker run -it --rm -p 5000:5000 -p 10001:10001 -p 10002:10002 -p 10003:10003 fay
|
||||
```
|
||||
## **镜像快速启动**
|
||||
|
||||
https://www.compshare.cn/images/compshareImage-1cft3sk9gvta
|
||||
|
||||
## **高级玩法**
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
FROM docker.m.daocloud.io/python:3.12
|
||||
#FROM python:3.12 ---> Nick
|
||||
COPY app /app
|
||||
RUN chmod +x /app/docker/install_deps.sh \
|
||||
# && mv /app/docker/sources.list /etc/apt/sources.list \ ---> 添加对应的sources list可以提升apt install 效率
|
||||
&& /app/docker/install_deps.sh \
|
||||
&& pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/ \
|
||||
&& pip install --no-cache-dir -r /app/docker/requirements.txt
|
||||
WORKDIR /app
|
||||
CMD ["python", "main.py"]
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
requests
|
||||
numpy
|
||||
pyaudio~=0.2.11
|
||||
websockets~=10.4
|
||||
ws4py~=0.5.1
|
||||
PyQt5==5.15.10
|
||||
PyQt5-sip==12.13.0
|
||||
PyQtWebEngine==5.15.6
|
||||
flask~=3.0.0
|
||||
openpyxl~=3.0.9
|
||||
flask_cors~=3.0.10
|
||||
websocket-client
|
||||
azure-cognitiveservices-speech
|
||||
aliyun-python-sdk-core
|
||||
simhash
|
||||
pytz
|
||||
gevent
|
||||
edge_tts
|
||||
pydub
|
||||
tenacity==8.2.3
|
||||
pygame
|
||||
scipy
|
||||
flask-httpauth
|
||||
opencv-python
|
||||
psutil
|
||||
langchain
|
||||
langchain_openai
|
||||
langgraph
|
||||
bs4
|
||||
schedule
|
||||
mcp
|
||||
+12
-1
@@ -7,6 +7,7 @@ import time
|
||||
from contextlib import AsyncExitStack
|
||||
from mcp import ClientSession
|
||||
from mcp.client.sse import sse_client
|
||||
from utils import util
|
||||
|
||||
# 设置日志记录
|
||||
logging.basicConfig(level=logging.ERROR)
|
||||
@@ -138,7 +139,17 @@ class McpClient:
|
||||
:param params: 参数字典
|
||||
:return: (是否成功, 结果或错误信息)
|
||||
"""
|
||||
return self.event_loop.run_until_complete(self._call_tool_async(method, params))
|
||||
try:
|
||||
# 确保在同一个事件循环中执行
|
||||
if asyncio.get_event_loop() != self.event_loop:
|
||||
return self.event_loop.run_until_complete(self._call_tool_async(method, params))
|
||||
else:
|
||||
# 如果已经在事件循环中,创建一个新的任务并等待它完成
|
||||
future = asyncio.run_coroutine_threadsafe(self._call_tool_async(method, params), self.event_loop)
|
||||
return future.result(timeout=30)
|
||||
except Exception as e:
|
||||
util.log(1, f"调用MCP工具时出错: {str(e)}")
|
||||
return False, f"调用工具失败: {str(e)}"
|
||||
|
||||
def list_tools(self):
|
||||
"""
|
||||
|
||||
@@ -171,7 +171,7 @@ class GenerativeAgent:
|
||||
Returns:
|
||||
None
|
||||
"""
|
||||
self.memory_stream.reflect(anchor, time_step)
|
||||
self.memory_stream.reflect(anchor, time_step=time_step)
|
||||
|
||||
|
||||
def categorical_resp(self, questions):
|
||||
|
||||
@@ -108,7 +108,7 @@ def init_memory_scheduler():
|
||||
schedule.every().day.at("00:00").do(save_agent_memory)
|
||||
|
||||
# 设置每天晚上11点执行反思
|
||||
schedule.every().day.at("23:00").do(perform_daily_reflection)
|
||||
schedule.every().day.at("09:41").do(perform_daily_reflection)
|
||||
|
||||
# 启动定时任务线程
|
||||
scheduler_thread = MyThread(target=memory_scheduler_thread)
|
||||
@@ -140,12 +140,12 @@ def check_memory_files(username=None):
|
||||
if os.path.exists(memory_cleared_flag_file):
|
||||
try:
|
||||
os.remove(memory_cleared_flag_file)
|
||||
util.log(1, f"删除记忆清除标记文件: {memory_cleared_flag_file}")
|
||||
util.log(1, f"清除删除记忆标记文件: {memory_cleared_flag_file}")
|
||||
# 重置记忆清除标记
|
||||
global memory_cleared
|
||||
memory_cleared = False
|
||||
except Exception as e:
|
||||
util.log(1, f"删除记忆清除标记文件时出错: {str(e)}")
|
||||
util.log(1, f"清除删除记忆标记文件时出错: {str(e)}")
|
||||
|
||||
# 检查meta.json是否存在
|
||||
meta_file = os.path.join(memory_dir, "meta.json")
|
||||
@@ -384,9 +384,8 @@ def question(content, username, observation=None):
|
||||
{context}
|
||||
{observation}
|
||||
"""
|
||||
|
||||
# 构建消息列表
|
||||
messages = [SystemMessage(content=system_prompt), HumanMessage(content=content)]
|
||||
messages = [SystemMessage(content=system_prompt), HumanMessage(content=content + "/no_think")]
|
||||
# 1. 获取mcp工具
|
||||
mcp_tools = get_mcp_tools()
|
||||
# 2. 存在mcp工具,走react agent
|
||||
@@ -565,7 +564,7 @@ def perform_daily_reflection():
|
||||
for username, agent in agents.items():
|
||||
# 获取当前时间作为time_step
|
||||
current_time_step = get_current_time_step(username)
|
||||
agent.reflect(topic, current_time_step)
|
||||
agent.reflect(topic, time_step=current_time_step)
|
||||
|
||||
# 记录反思执行情况
|
||||
util.log(1, f"反思主题: {topic}")
|
||||
|
||||
Reference in New Issue
Block a user