mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
query只传递相关的文本
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import traceback
|
||||
|
||||
from ..base import MemoryProviderBase, logger
|
||||
@@ -56,7 +57,16 @@ class MemoryProvider(MemoryProviderBase):
|
||||
|
||||
filters = {"user_id": self.role_id}
|
||||
|
||||
results = self.client.search(query, filters=filters)
|
||||
search_query = query
|
||||
try:
|
||||
if query.strip().startswith("{") and query.strip().endswith("}"):
|
||||
data = json.loads(query)
|
||||
if "content" in data:
|
||||
search_query = data["content"]
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
pass
|
||||
|
||||
results = self.client.search(search_query, filters=filters)
|
||||
if not results or "results" not in results:
|
||||
return ""
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import traceback
|
||||
from typing import Optional, Dict, Any
|
||||
|
||||
@@ -207,7 +208,7 @@ class MemoryProvider(MemoryProviderBase):
|
||||
Query memories from PowerMem based on similarity search.
|
||||
|
||||
Args:
|
||||
query: The search query string
|
||||
query: The search query string (may be JSON format with metadata)
|
||||
|
||||
Returns:
|
||||
Formatted string of relevant memories or empty string if none found
|
||||
@@ -221,6 +222,17 @@ class MemoryProvider(MemoryProviderBase):
|
||||
logger.bind(tag=TAG).debug("No role_id set, returning empty memory")
|
||||
return ""
|
||||
|
||||
# Extract content from JSON format if present (for ASR with emotion/language tags)
|
||||
search_query = query
|
||||
try:
|
||||
if query.strip().startswith("{") and query.strip().endswith("}"):
|
||||
data = json.loads(query)
|
||||
if "content" in data:
|
||||
search_query = data["content"]
|
||||
except (json.JSONDecodeError, KeyError):
|
||||
# If parsing fails, use original query
|
||||
pass
|
||||
|
||||
result_parts = []
|
||||
|
||||
# If user profile mode is enabled, include user profile in results
|
||||
@@ -234,14 +246,14 @@ class MemoryProvider(MemoryProviderBase):
|
||||
# UserMemory uses sync search
|
||||
results = await asyncio.to_thread(
|
||||
self.memory_client.search,
|
||||
query=query,
|
||||
query=search_query,
|
||||
user_id=self.role_id,
|
||||
limit=30
|
||||
)
|
||||
else:
|
||||
# AsyncMemory uses async search
|
||||
results = await self.memory_client.search(
|
||||
query=query,
|
||||
query=search_query,
|
||||
user_id=self.role_id,
|
||||
limit=30
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user