mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 01:23:55 +08:00
Merge branch 'main' into py-audio-aec
This commit is contained in:
@@ -43,9 +43,13 @@ class ASRProvider(ASRProviderBase):
|
||||
|
||||
# 内存检测,要求大于2G
|
||||
min_mem_bytes = 2 * 1024 * 1024 * 1024
|
||||
total_mem = psutil.virtual_memory().total
|
||||
if total_mem < min_mem_bytes:
|
||||
logger.bind(tag=TAG).error(f"可用内存不足2G,当前仅有 {total_mem / (1024*1024):.2f} MB,可能无法启动FunASR")
|
||||
try:
|
||||
total_mem = psutil.virtual_memory().total
|
||||
except RuntimeError as e:
|
||||
logger.bind(tag=TAG).warning(f"获取系统内存信息失败,跳过FunASR内存检测: {e}")
|
||||
else:
|
||||
if total_mem < min_mem_bytes:
|
||||
logger.bind(tag=TAG).error(f"可用内存不足2G,当前仅有 {total_mem / (1024*1024):.2f} MB,可能无法启动FunASR")
|
||||
|
||||
self.interface_type = InterfaceType.LOCAL
|
||||
self.model_dir = config.get("model_dir")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
from ..base import MemoryProviderBase, logger
|
||||
@@ -59,7 +60,9 @@ class MemoryProvider(MemoryProviderBase):
|
||||
|
||||
messages.append({"role": message.role, "content": content})
|
||||
|
||||
result = self.client.add(messages, user_id=self.role_id)
|
||||
result = await asyncio.to_thread(
|
||||
self.client.add, messages, user_id=self.role_id
|
||||
)
|
||||
logger.bind(tag=TAG).debug(f"Save memory result: {result}")
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"保存记忆失败: {str(e)}")
|
||||
@@ -84,7 +87,9 @@ class MemoryProvider(MemoryProviderBase):
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
pass
|
||||
|
||||
results = self.client.search(search_query, filters=filters)
|
||||
results = await asyncio.to_thread(
|
||||
self.client.search, search_query, filters=filters
|
||||
)
|
||||
if not results or "results" not in results:
|
||||
return ""
|
||||
|
||||
|
||||
@@ -186,13 +186,19 @@ class MemoryProvider(MemoryProviderBase):
|
||||
messages.append({"role": message.role, "content": content})
|
||||
|
||||
# Add memory using PowerMem SDK
|
||||
result = self.memory_client.add(
|
||||
messages=messages,
|
||||
user_id=self.role_id
|
||||
)
|
||||
# Handle both sync and async returns
|
||||
if asyncio.iscoroutine(result):
|
||||
result = await result
|
||||
if self.enable_user_profile:
|
||||
# UserMemory uses sync add
|
||||
result = await asyncio.to_thread(
|
||||
self.memory_client.add,
|
||||
messages=messages,
|
||||
user_id=self.role_id
|
||||
)
|
||||
else:
|
||||
# AsyncMemory uses async add
|
||||
result = await self.memory_client.add(
|
||||
messages=messages,
|
||||
user_id=self.role_id
|
||||
)
|
||||
|
||||
logger.bind(tag=TAG).debug(f"Save memory result: {result}")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""服务端插件工具执行器"""
|
||||
|
||||
import asyncio
|
||||
from typing import Dict, Any, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -41,6 +42,10 @@ class ServerPluginExecutor(ToolExecutor):
|
||||
# 默认不传conn参数
|
||||
result = func_item.func(**arguments)
|
||||
|
||||
# 兼容 async def 工具函数
|
||||
if asyncio.iscoroutine(result):
|
||||
result = await result
|
||||
|
||||
return result
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user