Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/memos/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
24 changes: 14 additions & 10 deletions src/memos/api/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 7 additions & 5 deletions src/memos/mem_os/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/memos/mem_os/product_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down