🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -18,16 +18,17 @@ async def forced_change_subheartflow_status(subheartflow_id: str, status: ChatSt
|
|||||||
return await heartflow.force_change_subheartflow_status(subheartflow_id, status)
|
return await heartflow.force_change_subheartflow_status(subheartflow_id, status)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def get_subheartflow_cycle_info(subheartflow_id: str, history_len: int) -> dict:
|
async def get_subheartflow_cycle_info(subheartflow_id: str, history_len: int) -> dict:
|
||||||
"""获取子心流的循环信息"""
|
"""获取子心流的循环信息"""
|
||||||
subheartflow_cycle_info = await heartflow.api_get_subheartflow_cycle_info(subheartflow_id, history_len)
|
subheartflow_cycle_info = await heartflow.api_get_subheartflow_cycle_info(subheartflow_id, history_len)
|
||||||
logger.debug(f"子心流 {subheartflow_id} 循环信息: {subheartflow_cycle_info}")
|
logger.debug(f"子心流 {subheartflow_id} 循环信息: {subheartflow_cycle_info}")
|
||||||
if subheartflow_cycle_info:
|
if subheartflow_cycle_info:
|
||||||
return subheartflow_cycle_info
|
return subheartflow_cycle_info
|
||||||
else:
|
else:
|
||||||
logger.warning(f"子心流 {subheartflow_id} 循环信息未找到")
|
logger.warning(f"子心流 {subheartflow_id} 循环信息未找到")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def get_all_states():
|
async def get_all_states():
|
||||||
"""获取所有状态"""
|
"""获取所有状态"""
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from fastapi import APIRouter
|
|||||||
from strawberry.fastapi import GraphQLRouter
|
from strawberry.fastapi import GraphQLRouter
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# from src.heart_flow.heartflow import heartflow
|
# from src.heart_flow.heartflow import heartflow
|
||||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
||||||
# from src.config.config import BotConfig
|
# from src.config.config import BotConfig
|
||||||
@@ -9,7 +10,7 @@ from src.common.logger_manager import get_logger
|
|||||||
from src.api.reload_config import reload_config as reload_config_func
|
from src.api.reload_config import reload_config as reload_config_func
|
||||||
from src.common.server import global_server
|
from src.common.server import global_server
|
||||||
from src.api.apiforgui import (
|
from src.api.apiforgui import (
|
||||||
get_all_subheartflow_ids,
|
get_all_subheartflow_ids,
|
||||||
forced_change_subheartflow_status,
|
forced_change_subheartflow_status,
|
||||||
get_subheartflow_cycle_info,
|
get_subheartflow_cycle_info,
|
||||||
get_all_states,
|
get_all_states,
|
||||||
@@ -72,7 +73,8 @@ async def force_stop_maibot():
|
|||||||
else:
|
else:
|
||||||
logger.error("MAI Bot强制停止失败")
|
logger.error("MAI Bot强制停止失败")
|
||||||
return {"status": "failed"}
|
return {"status": "failed"}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/gui/subheartflow/cycleinfo")
|
@router.get("/gui/subheartflow/cycleinfo")
|
||||||
async def get_subheartflow_cycle_info_api(subheartflow_id: str, history_len: int):
|
async def get_subheartflow_cycle_info_api(subheartflow_id: str, history_len: int):
|
||||||
"""获取子心流的循环信息"""
|
"""获取子心流的循环信息"""
|
||||||
@@ -83,6 +85,7 @@ async def get_subheartflow_cycle_info_api(subheartflow_id: str, history_len: int
|
|||||||
logger.warning(f"子心流 {subheartflow_id} 循环信息未找到")
|
logger.warning(f"子心流 {subheartflow_id} 循环信息未找到")
|
||||||
return {"status": "failed", "reason": "subheartflow not found"}
|
return {"status": "failed", "reason": "subheartflow not found"}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/gui/get_all_states")
|
@router.get("/gui/get_all_states")
|
||||||
async def get_all_states_api():
|
async def get_all_states_api():
|
||||||
"""获取所有状态"""
|
"""获取所有状态"""
|
||||||
@@ -93,6 +96,7 @@ async def get_all_states_api():
|
|||||||
logger.warning("获取所有状态失败")
|
logger.warning("获取所有状态失败")
|
||||||
return {"status": "failed", "reason": "failed to get all states"}
|
return {"status": "failed", "reason": "failed to get all states"}
|
||||||
|
|
||||||
|
|
||||||
def start_api_server():
|
def start_api_server():
|
||||||
"""启动API服务器"""
|
"""启动API服务器"""
|
||||||
global_server.register_router(router, prefix="/api/v1")
|
global_server.register_router(router, prefix="/api/v1")
|
||||||
|
|||||||
@@ -66,12 +66,11 @@ class Heartflow:
|
|||||||
"""强制改变子心流的状态"""
|
"""强制改变子心流的状态"""
|
||||||
# 这里的 message 是可选的,可能是一个消息对象,也可能是其他类型的数据
|
# 这里的 message 是可选的,可能是一个消息对象,也可能是其他类型的数据
|
||||||
return await self.subheartflow_manager.force_change_state(subheartflow_id, status)
|
return await self.subheartflow_manager.force_change_state(subheartflow_id, status)
|
||||||
|
|
||||||
async def api_get_all_states(self):
|
async def api_get_all_states(self):
|
||||||
"""获取所有状态"""
|
"""获取所有状态"""
|
||||||
return await self.interest_logger.api_get_all_states()
|
return await self.interest_logger.api_get_all_states()
|
||||||
|
|
||||||
|
|
||||||
async def api_get_subheartflow_cycle_info(self, subheartflow_id: str, history_len: int) -> Optional[dict]:
|
async def api_get_subheartflow_cycle_info(self, subheartflow_id: str, history_len: int) -> Optional[dict]:
|
||||||
"""获取子心流的循环信息"""
|
"""获取子心流的循环信息"""
|
||||||
subheartflow = await self.subheartflow_manager.get_or_create_subheartflow(subheartflow_id)
|
subheartflow = await self.subheartflow_manager.get_or_create_subheartflow(subheartflow_id)
|
||||||
@@ -82,7 +81,7 @@ class Heartflow:
|
|||||||
if not heartfc_instance:
|
if not heartfc_instance:
|
||||||
logger.warning(f"子心流 {subheartflow_id} 没有心流实例,无法获取周期信息")
|
logger.warning(f"子心流 {subheartflow_id} 没有心流实例,无法获取周期信息")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return heartfc_instance.get_cycle_history(last_n=history_len)
|
return heartfc_instance.get_cycle_history(last_n=history_len)
|
||||||
|
|
||||||
async def heartflow_start_working(self):
|
async def heartflow_start_working(self):
|
||||||
|
|||||||
@@ -209,4 +209,4 @@ class InterestLogger:
|
|||||||
return subflow_details
|
return subflow_details
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"记录状态时发生意外错误: {e}")
|
logger.error(f"记录状态时发生意外错误: {e}")
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
|
|||||||
Reference in New Issue
Block a user