Merge branch 'dev' of https://github.com/MoFox-Studio/MoFox_Bot into dev
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
"""
|
||||
|
||||
import time
|
||||
import orjson
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import orjson
|
||||
|
||||
from src.chat.interest_system import bot_interest_manager
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config import global_config
|
||||
|
||||
@@ -230,11 +230,11 @@ class ChatterPlanExecutor:
|
||||
except Exception as e:
|
||||
error_message = str(e)
|
||||
logger.error(f"执行回复动作失败: {action_info.action_type}, 错误: {error_message}")
|
||||
'''
|
||||
"""
|
||||
# 记录用户关系追踪
|
||||
if success and action_info.action_message:
|
||||
await self._track_user_interaction(action_info, plan, reply_content)
|
||||
'''
|
||||
"""
|
||||
execution_time = time.time() - start_time
|
||||
self.execution_stats["execution_times"].append(execution_time)
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ from typing import TYPE_CHECKING, Any
|
||||
from src.common.logger import get_logger
|
||||
from src.config.config import global_config
|
||||
from src.mood.mood_manager import mood_manager
|
||||
from src.plugin_system.base.component_types import ChatMode
|
||||
from src.plugins.built_in.affinity_flow_chatter.plan_executor import ChatterPlanExecutor
|
||||
from src.plugins.built_in.affinity_flow_chatter.plan_filter import ChatterPlanFilter
|
||||
from src.plugins.built_in.affinity_flow_chatter.plan_generator import ChatterPlanGenerator
|
||||
from src.plugin_system.base.component_types import ChatMode
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from src.chat.planner_actions.action_manager import ChatterActionManager
|
||||
|
||||
@@ -6,9 +6,7 @@ SearXNG search engine implementation
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import functools
|
||||
from typing import Any, List
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
@@ -39,13 +37,13 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
instances = config_api.get_global_config("web_search.searxng_instances", None)
|
||||
if isinstance(instances, list):
|
||||
# 过滤空值
|
||||
self.instances: List[str] = [u.rstrip("/") for u in instances if isinstance(u, str) and u.strip()]
|
||||
self.instances: list[str] = [u.rstrip("/") for u in instances if isinstance(u, str) and u.strip()]
|
||||
else:
|
||||
self.instances = []
|
||||
|
||||
api_keys = config_api.get_global_config("web_search.searxng_api_keys", None)
|
||||
if isinstance(api_keys, list):
|
||||
self.api_keys: List[str | None] = [k.strip() if isinstance(k, str) and k.strip() else None for k in api_keys]
|
||||
self.api_keys: list[str | None] = [k.strip() if isinstance(k, str) and k.strip() else None for k in api_keys]
|
||||
else:
|
||||
self.api_keys = []
|
||||
|
||||
@@ -85,7 +83,7 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
results.extend(instance_results)
|
||||
if len(results) >= num_results:
|
||||
break
|
||||
except Exception as e: # noqa: BLE001
|
||||
except Exception as e:
|
||||
logger.warning(f"SearXNG 实例 {base_url} 调用失败: {e}")
|
||||
continue
|
||||
|
||||
@@ -116,12 +114,12 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
try:
|
||||
resp = await self._client.get(url, params=params, headers=headers)
|
||||
resp.raise_for_status()
|
||||
except Exception as e: # noqa: BLE001
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"请求失败: {e}") from e
|
||||
|
||||
try:
|
||||
data = resp.json()
|
||||
except Exception as e: # noqa: BLE001
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"解析 JSON 失败: {e}") from e
|
||||
|
||||
raw_results = data.get("results", []) if isinstance(data, dict) else []
|
||||
@@ -141,5 +139,5 @@ class SearXNGSearchEngine(BaseSearchEngine):
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc, tb): # noqa: D401
|
||||
async def __aexit__(self, exc_type, exc, tb):
|
||||
await self._client.aclose()
|
||||
|
||||
@@ -41,8 +41,8 @@ class WEBSEARCHPLUGIN(BasePlugin):
|
||||
from .engines.bing_engine import BingSearchEngine
|
||||
from .engines.ddg_engine import DDGSearchEngine
|
||||
from .engines.exa_engine import ExaSearchEngine
|
||||
from .engines.tavily_engine import TavilySearchEngine
|
||||
from .engines.searxng_engine import SearXNGSearchEngine
|
||||
from .engines.tavily_engine import TavilySearchEngine
|
||||
|
||||
# 实例化所有搜索引擎,这会触发API密钥管理器的初始化
|
||||
exa_engine = ExaSearchEngine()
|
||||
|
||||
@@ -13,8 +13,8 @@ from src.plugin_system.apis import config_api
|
||||
from ..engines.bing_engine import BingSearchEngine
|
||||
from ..engines.ddg_engine import DDGSearchEngine
|
||||
from ..engines.exa_engine import ExaSearchEngine
|
||||
from ..engines.tavily_engine import TavilySearchEngine
|
||||
from ..engines.searxng_engine import SearXNGSearchEngine
|
||||
from ..engines.tavily_engine import TavilySearchEngine
|
||||
from ..utils.formatters import deduplicate_results, format_search_results
|
||||
|
||||
logger = get_logger("web_search_tool")
|
||||
|
||||
Reference in New Issue
Block a user