[Refactor] Improve logging package wide (#1315)

This commit is contained in:
Deshraj Yadav
2024-03-13 17:13:30 -07:00
committed by GitHub
parent ef69c91b60
commit 3616eaadb4
54 changed files with 263 additions and 231 deletions

View File

@@ -8,6 +8,8 @@ from embedchain.core.db.models import ChatHistory as ChatHistoryModel
from embedchain.memory.message import ChatMessage
from embedchain.memory.utils import merge_metadata_dict
logger = logging.getLogger(__name__)
class ChatHistory:
def __init__(self) -> None:
@@ -31,11 +33,11 @@ class ChatHistory:
try:
self.db_session.commit()
except Exception as e:
logging.error(f"Error adding chat memory to db: {e}")
logger.error(f"Error adding chat memory to db: {e}")
self.db_session.rollback()
return None
logging.info(f"Added chat memory to db with id: {memory_id}")
logger.info(f"Added chat memory to db with id: {memory_id}")
return memory_id
def delete(self, app_id: str, session_id: Optional[str] = None):
@@ -55,7 +57,7 @@ class ChatHistory:
try:
self.db_session.commit()
except Exception as e:
logging.error(f"Error deleting chat history: {e}")
logger.error(f"Error deleting chat history: {e}")
self.db_session.rollback()
def get(

View File

@@ -3,6 +3,8 @@ from typing import Any, Optional
from embedchain.helpers.json_serializable import JSONSerializable
logger = logging.getLogger(__name__)
class BaseMessage(JSONSerializable):
"""
@@ -52,7 +54,7 @@ class ChatMessage(JSONSerializable):
def add_user_message(self, message: str, metadata: Optional[dict] = None):
if self.human_message:
logging.info(
logger.info(
"Human message already exists in the chat message,\
overwriting it with new message."
)
@@ -61,7 +63,7 @@ class ChatMessage(JSONSerializable):
def add_ai_message(self, message: str, metadata: Optional[dict] = None):
if self.ai_message:
logging.info(
logger.info(
"AI message already exists in the chat message,\
overwriting it with new message."
)