Skip to content
Open
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
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ issues = "https://github.com/MemTensor/MemOS/issues"
[project.scripts]
memos = "memos.cli:main"

[project.entry-points."memos.plugins"]
dream = "memos.dream:CommunityDreamPlugin"

[project.optional-dependencies]
# These are optional dependencies for various features of MemoryOS.
# Developers install: `poetry install --extras <feature>`. e.g., `poetry install --extras general-mem`
Expand Down
8 changes: 6 additions & 2 deletions src/memos/api/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(
self,
dependencies: HandlerDependencies,
chat_llms: dict[str, Any],
playground_chat_llms: dict[str, Any] | None = None,
search_handler=None,
add_handler=None,
online_bot=None,
Expand All @@ -70,6 +71,7 @@ def __init__(
Args:
dependencies: HandlerDependencies instance
chat_llms: Dictionary mapping model names to LLM instances
playground_chat_llms: Optional model map for /chat/stream/playground
search_handler: Optional SearchHandler instance (created if not provided)
add_handler: Optional AddHandler instance (created if not provided)
online_bot: Optional DingDing bot function for notifications
Expand All @@ -89,6 +91,7 @@ def __init__(
add_handler = AddHandler(dependencies)

self.chat_llms = chat_llms
self.playground_chat_llms = playground_chat_llms or chat_llms
self.search_handler = search_handler
self.add_handler = add_handler
self.online_bot = online_bot
Expand Down Expand Up @@ -630,10 +633,11 @@ def generate_chat_response() -> Generator[str, None, None]:

# Step 3: Generate streaming response from LLM
try:
model = next(iter(self.chat_llms.keys()))
chat_llms = self.playground_chat_llms
model = next(iter(chat_llms.keys()))
self.logger.info(f"[PLAYGROUND CHAT] Chat Playground Stream Model: {model}")
start = time.time()
response_stream = self.chat_llms[model].generate_stream(
response_stream = chat_llms[model].generate_stream(
current_messages, model_name_or_path=model
)

Expand Down
7 changes: 7 additions & 0 deletions src/memos/api/handlers/component_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def init_server() -> dict[str, Any]:
graph_db_config = build_graph_db_config()
llm_config = build_llm_config()
chat_llm_config = build_chat_llm_config()
playground_chat_llm_config = build_chat_llm_config("PLAYGROUND_CHAT_MODEL_LIST")
embedder_config = build_embedder_config()
nli_client_config = build_nli_client_config()
mem_reader_config = build_mem_reader_config()
Expand All @@ -174,6 +175,11 @@ def init_server() -> dict[str, Any]:
if os.getenv("ENABLE_CHAT_API", "false") == "true"
else None
)
playground_chat_llms = (
_init_chat_llms(playground_chat_llm_config)
if os.getenv("ENABLE_CHAT_API", "false") == "true" and playground_chat_llm_config
else chat_llms
)
embedder = EmbedderFactory.from_config(embedder_config)

plugin_context = build_plugin_context(
Expand Down Expand Up @@ -317,6 +323,7 @@ def init_server() -> dict[str, Any]:
"mem_reader": mem_reader,
"llm": llm,
"chat_llms": chat_llms,
"playground_chat_llms": playground_chat_llms,
"embedder": embedder,
"reranker": reranker,
"internet_retriever": internet_retriever,
Expand Down
7 changes: 5 additions & 2 deletions src/memos/api/handlers/config_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,17 @@ def build_llm_config() -> dict[str, Any]:
)


def build_chat_llm_config() -> list[dict[str, Any]]:
def build_chat_llm_config(env_name: str = "CHAT_MODEL_LIST") -> list[dict[str, Any]]:
"""
Build chat LLM configuration.

Returns:
Validated chat LLM configuration dictionary
Args:
env_name: Environment variable that contains the JSON chat model list.

"""
configs = json.loads(os.getenv("CHAT_MODEL_LIST", "[]"))
configs = json.loads(os.getenv(env_name, "[]"))
return [
{
"config_class": LLMConfigFactory.model_validate(
Expand Down
11 changes: 10 additions & 1 deletion src/memos/api/handlers/search_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
from memos.multi_mem_cube.composite_cube import CompositeCubeView
from memos.multi_mem_cube.single_cube import SingleCubeView
from memos.multi_mem_cube.views import MemCubeView
from memos.plugins.hooks import hookable
from memos.plugins.hook_defs import H
from memos.plugins.hooks import hookable, trigger_hook


logger = get_logger(__name__)
Expand Down Expand Up @@ -71,6 +72,14 @@ def handle_search_memories(self, search_req: APISearchRequest) -> SearchResponse
# Search and deduplicate
cube_view = self._build_cube_view(search_req_local)
results = cube_view.search_memories(search_req_local)
hooked_results = trigger_hook(
H.SEARCH_MEMORY_RESULTS,
handler=self,
search_req=search_req_local,
results=results,
)
if hooked_results is not None:
results = hooked_results
if not search_req_local.relativity:
search_req_local.relativity = 0
self.logger.info(f"[SearchHandler] Relativity filter: {search_req_local.relativity}")
Expand Down
9 changes: 5 additions & 4 deletions src/memos/api/routers/server_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
add_handler = AddHandler(dependencies)
chat_handler = (
ChatHandler(
dependencies,
components["chat_llms"],
search_handler,
add_handler,
dependencies=dependencies,
chat_llms=components["chat_llms"],
playground_chat_llms=components.get("playground_chat_llms"),
search_handler=search_handler,
add_handler=add_handler,
online_bot=components.get("online_bot"),
)
if os.getenv("ENABLE_CHAT_API", "false") == "true"
Expand Down
Loading
Loading