diff --git a/src/memos/api/client.py b/src/memos/api/client.py index 581076cb2..0beebab9a 100644 --- a/src/memos/api/client.py +++ b/src/memos/api/client.py @@ -31,7 +31,12 @@ class MemOSClient: """MemOS API client""" - def __init__(self, api_key: str | None = None, base_url: str | None = None, is_global: str | bool = "false"): + def __init__( + self, + api_key: str | None = None, + base_url: str | None = None, + is_global: str | bool = "false", + ): # Priority: # 1. base_url argument # 2. MEMOS_BASE_URL environment variable (direct URL) @@ -44,11 +49,9 @@ def __init__(self, api_key: str | None = None, base_url: str | None = None, is_g if final_is_global else "https://memos.memtensor.cn/api/openmem/v1" ) - self.base_url = base_url or os.getenv("MEMOS_BASE_URL") or default_url - api_key = api_key or os.getenv("MEMOS_API_KEY") if not api_key: diff --git a/src/memos/api/handlers/chat_handler.py b/src/memos/api/handlers/chat_handler.py index fe250bbd6..58a271f34 100644 --- a/src/memos/api/handlers/chat_handler.py +++ b/src/memos/api/handlers/chat_handler.py @@ -1514,12 +1514,14 @@ def run_async_in_thread(): ) # Add exception handling for the background task task.add_done_callback( - lambda t: self.logger.error( - f"Error in background post-chat processing for user {user_id}: {t.exception()}", - exc_info=True, + lambda t: ( + self.logger.error( + f"Error in background post-chat processing for user {user_id}: {t.exception()}", + exc_info=True, + ) + if t.exception() + else None ) - if t.exception() - else None ) except RuntimeError: # No event loop, run in a new thread with context propagation @@ -1581,12 +1583,14 @@ def run_async_in_thread(): ) ) task.add_done_callback( - lambda t: self.logger.error( - f"Error in background add to memory for user {user_id}: {t.exception()}", - exc_info=True, + lambda t: ( + self.logger.error( + f"Error in background add to memory for user {user_id}: {t.exception()}", + exc_info=True, + ) + if t.exception() + else None ) - if t.exception() - else None ) except RuntimeError: thread = ContextThread( diff --git a/src/memos/mem_os/product.py b/src/memos/mem_os/product.py index 77a5e70c9..b2c74c384 100644 --- a/src/memos/mem_os/product.py +++ b/src/memos/mem_os/product.py @@ -798,12 +798,14 @@ def run_async_in_thread(): ) # Add exception handling for the background task task.add_done_callback( - lambda t: logger.error( - f"Error in background post-chat processing for user {user_id}: {t.exception()}", - exc_info=True, + lambda t: ( + logger.error( + f"Error in background post-chat processing for user {user_id}: {t.exception()}", + exc_info=True, + ) + if t.exception() + else None ) - if t.exception() - else None ) except RuntimeError: # No event loop, run in a new thread with context propagation diff --git a/src/memos/mem_os/product_server.py b/src/memos/mem_os/product_server.py index 758f2794d..80aefea85 100644 --- a/src/memos/mem_os/product_server.py +++ b/src/memos/mem_os/product_server.py @@ -437,12 +437,14 @@ def run_async_in_thread(): ) # Add exception handling for the background task task.add_done_callback( - lambda t: logger.error( - f"Error in background post-chat processing for user {user_id}: {t.exception()}", - exc_info=True, + lambda t: ( + logger.error( + f"Error in background post-chat processing for user {user_id}: {t.exception()}", + exc_info=True, + ) + if t.exception() + else None ) - if t.exception() - else None ) except RuntimeError: # No event loop, run in a new thread with context propagation