From 0a1932a89bda8dc7d4d9f283ed61432288eca5f3 Mon Sep 17 00:00:00 2001 From: auctor Date: Wed, 22 Apr 2026 23:40:36 +0000 Subject: [PATCH] fix(suggestion_handler): split system+user so non-OpenAI LLMs accept the request handle_get_suggestion_queries built a message list with a single system role. OpenAI accepts that shape; several other LLM backends do not: - MiniMax (Text API at https://api.minimax.io/v1/chat/completions) rejects with HTTP 400 'invalid params, chat content is empty (2013)'. - MiniMax Anthropic-compatible API (https://api.minimax.io/anthropic/v1/messages) rejects with HTTP 400 'invalid params, messages must not be empty (2013)'. - The official Anthropic Messages API has the same requirement (system is a top-level field; messages[] must contain at least one user turn). Move the suggestion prompt into a user message and keep a short system role for the persona. OpenAI and other strict-schema providers both accept this shape, so it is a strict widening with no behaviour change for OpenAI/Azure deployments. Repro of the original bug: POST /product/suggestions with MOS_CHAT_MODEL=MiniMax-M2.7, OPENAI_API_BASE=https://api.minimax.io/v1 -> backend hits MiniMax which returns 400 (2013). --- src/memos/api/handlers/suggestion_handler.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/memos/api/handlers/suggestion_handler.py b/src/memos/api/handlers/suggestion_handler.py index a10251ec2..144e694a9 100644 --- a/src/memos/api/handlers/suggestion_handler.py +++ b/src/memos/api/handlers/suggestion_handler.py @@ -110,8 +110,21 @@ def handle_get_suggestion_queries( if text_mem_results: memories = "\n".join([m.memory[:200] for m in text_mem_results]) - # Generate suggestions using LLM - message_list = [{"role": "system", "content": suggestion_prompt.format(memories=memories)}] + # Generate suggestions using LLM. + # The prompt is split into system+user roles so the request stays + # valid for backends that reject system-only payloads (e.g. MiniMax + # `chat content is empty (2013)`, Anthropic `messages must not be empty`). + # OpenAI accepts either shape, so this is a safe widening. + message_list = [ + { + "role": "system", + "content": "You generate suggestion queries based on the user's recent memories.", + }, + { + "role": "user", + "content": suggestion_prompt.format(memories=memories), + }, + ] response = llm.generate(message_list) clean_response = clean_json_response(response) response_json = json.loads(clean_response)