refactor(logging): introduce centralized logging and FastAPI lifespan
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 2m38s
Some checks failed
Build and Push Docker / build-and-push (push) Failing after 2m38s
This commit is contained in:
@ -4,6 +4,9 @@ from datetime import datetime
|
||||
import openai
|
||||
import threading
|
||||
from mem0 import Memory
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Mem0Integration:
|
||||
@ -42,19 +45,19 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
memories = results.get("memories", results.get("results", []))
|
||||
return memories
|
||||
else:
|
||||
print(f"[ERROR] Unexpected search results format: {type(results)}")
|
||||
logger.error(f"Unexpected search results format: {type(results)}")
|
||||
return []
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to search memories: {e}")
|
||||
logger.error(f"Failed to search memories: {e}")
|
||||
return []
|
||||
|
||||
def add_memory(self, messages: List[Dict[str, str]], user_id: str, metadata: Optional[Dict] = None) -> Dict[str, Any]:
|
||||
"""Add a memory for the user."""
|
||||
try:
|
||||
# Debug: Print what we're trying to add
|
||||
print(f"[DEBUG] Adding memory for user {user_id}")
|
||||
print(f"[DEBUG] Messages: {messages}")
|
||||
print(f"[DEBUG] Metadata: {metadata}")
|
||||
# Debug: Log what we're trying to add
|
||||
logger.debug(f"Adding memory for user {user_id}")
|
||||
logger.debug(f"Messages: {messages}")
|
||||
logger.debug(f"Metadata: {metadata}")
|
||||
|
||||
result = self.memory.add(
|
||||
messages=messages,
|
||||
@ -63,13 +66,12 @@ In your response, consider the memories above to provide a personalized answer."
|
||||
infer= False
|
||||
)
|
||||
|
||||
# Debug: Print the result
|
||||
print(f"[DEBUG] Add memory result: {result}")
|
||||
# Debug: Log the result
|
||||
logger.debug(f"Add memory result: {result}")
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Failed to add memory: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
logger.error(f"Failed to add memory: {e}")
|
||||
logger.exception("Exception details:")
|
||||
return {}
|
||||
|
||||
def format_memories_for_prompt(self, memories: List[Any]) -> str:
|
||||
|
Reference in New Issue
Block a user