diff --git a/docs/openapi.json b/docs/openapi.json index 46d715147..11ac3d8f7 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -1,21 +1,23 @@ { "openapi": "3.1.0", "info": { - "title": "MemOS REST APIs", - "description": "A REST API for managing and searching memories using MemOS.", + "title": "MemOS API", "version": "1.0.0" }, "paths": { - "/configure": { + "/product/search": { "post": { - "summary": "Configure MemOS", - "description": "Set MemOS configuration.", - "operationId": "set_config_configure_post", + "tags": [ + "Server API" + ], + "summary": "Search memories", + "description": "Search memories for a specific user.\n\nThis endpoint uses the class-based SearchHandler for better code organization.", + "operationId": "search_memories_product_search_post", "requestBody": { "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/MOSConfig" + "$ref": "#/components/schemas/APISearchRequest" } } }, @@ -27,7 +29,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ConfigResponse" + "$ref": "#/components/schemas/SearchResponse" } } } @@ -45,33 +47,19 @@ } } }, - "/users": { - "get": { - "summary": "List all users", - "description": "List all active users.", - "operationId": "list_users_users_get", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UserListResponse" - } - } - } - } - } - }, + "/product/add": { "post": { - "summary": "Create a new user", - "description": "Create a new user.", - "operationId": "create_user_users_post", + "tags": [ + "Server API" + ], + "summary": "Add memories", + "description": "Add memories for a specific user.\n\nThis endpoint uses the class-based AddHandler for better code organization.", + "operationId": "add_memories_product_add_post", "requestBody": { "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserCreate" + "$ref": "#/components/schemas/APIADDRequest" } } }, @@ -83,7 +71,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/UserResponse" + "$ref": "#/components/schemas/MemoryResponse" } } } @@ -101,57 +89,21 @@ } } }, - "/users/me": { + "/product/scheduler/allstatus": { "get": { - "summary": "Get current user info", - "description": "Get current user information including accessible cubes.", - "operationId": "get_user_info_users_me_get", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/UserResponse" - } - } - } - } - } - } - }, - "/mem_cubes": { - "post": { - "summary": "Register a MemCube", - "description": "Register a new MemCube.", - "operationId": "register_mem_cube_mem_cubes_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MemCubeRegister" - } - } - }, - "required": true - }, + "tags": [ + "Server API" + ], + "summary": "Get detailed scheduler status", + "description": "Get detailed scheduler status including running tasks and queue metrics.", + "operationId": "scheduler_allstatus_product_scheduler_allstatus_get", "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SimpleResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" + "$ref": "#/components/schemas/AllStatusResponse" } } } @@ -159,23 +111,28 @@ } } }, - "/mem_cubes/{mem_cube_id}": { - "delete": { - "summary": "Unregister a MemCube", - "description": "Unregister a MemCube.", - "operationId": "unregister_mem_cube_mem_cubes__mem_cube_id__delete", + "/product/scheduler/status": { + "get": { + "tags": [ + "Server API" + ], + "summary": "Get scheduler running status", + "description": "Get scheduler running status.", + "operationId": "scheduler_status_product_scheduler_status_get", "parameters": [ { - "name": "mem_cube_id", - "in": "path", + "name": "user_id", + "in": "query", "required": true, "schema": { "type": "string", - "title": "Mem Cube Id" - } + "description": "User ID", + "title": "User Id" + }, + "description": "User ID" }, { - "name": "user_id", + "name": "task_id", "in": "query", "required": false, "schema": { @@ -187,8 +144,10 @@ "type": "null" } ], - "title": "User Id" - } + "description": "Optional Task ID to query a specific task", + "title": "Task Id" + }, + "description": "Optional Task ID to query a specific task" } ], "responses": { @@ -197,7 +156,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SimpleResponse" + "$ref": "#/components/schemas/StatusResponse" } } } @@ -215,39 +174,34 @@ } } }, - "/mem_cubes/{cube_id}/share": { - "post": { - "summary": "Share a cube with another user", - "description": "Share a cube with another user.", - "operationId": "share_cube_mem_cubes__cube_id__share_post", + "/product/scheduler/task_queue_status": { + "get": { + "tags": [ + "Server API" + ], + "summary": "Get scheduler task queue status", + "description": "Get scheduler task queue backlog/pending status for a user.", + "operationId": "scheduler_task_queue_status_product_scheduler_task_queue_status_get", "parameters": [ { - "name": "cube_id", - "in": "path", + "name": "user_id", + "in": "query", "required": true, "schema": { "type": "string", - "title": "Cube Id" - } + "description": "User ID whose queue status is requested", + "title": "User Id" + }, + "description": "User ID whose queue status is requested" } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/CubeShare" - } - } - } - }, "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SimpleResponse" + "$ref": "#/components/schemas/TaskQueueResponse" } } } @@ -265,79 +219,42 @@ } } }, - "/memories": { + "/product/scheduler/wait": { "post": { - "summary": "Create memories", - "description": "Store new memories in a MemCube.", - "operationId": "add_memory_memories_post", - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/MemoryCreate" - } - } - } - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/SimpleResponse" - } - } + "tags": [ + "Server API" + ], + "summary": "Wait until scheduler is idle for a specific user", + "description": "Wait until scheduler is idle for a specific user.", + "operationId": "scheduler_wait_product_scheduler_wait_post", + "parameters": [ + { + "name": "user_name", + "in": "query", + "required": true, + "schema": { + "type": "string", + "title": "User Name" } }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - }, - "get": { - "summary": "Get all memories", - "description": "Retrieve all memories from a MemCube.", - "operationId": "get_all_memories_memories_get", - "parameters": [ { - "name": "mem_cube_id", + "name": "timeout_seconds", "in": "query", "required": false, "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Mem Cube Id" + "type": "number", + "default": 120.0, + "title": "Timeout Seconds" } }, { - "name": "user_id", + "name": "poll_interval", "in": "query", "required": false, "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "User Id" + "type": "number", + "default": 0.5, + "title": "Poll Interval" } } ], @@ -346,9 +263,7 @@ "description": "Successful Response", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/MemoryResponse" - } + "schema": {} } } }, @@ -365,44 +280,42 @@ } } }, - "/memories/{mem_cube_id}/{memory_id}": { + "/product/scheduler/wait/stream": { "get": { - "summary": "Get a memory", - "description": "Retrieve a specific memory by ID from a MemCube.", - "operationId": "get_memory_memories__mem_cube_id___memory_id__get", + "tags": [ + "Server API" + ], + "summary": "Stream scheduler progress for a user", + "description": "Stream scheduler progress via Server-Sent Events (SSE).", + "operationId": "scheduler_wait_stream_product_scheduler_wait_stream_get", "parameters": [ { - "name": "mem_cube_id", - "in": "path", + "name": "user_name", + "in": "query", "required": true, "schema": { "type": "string", - "title": "Mem Cube Id" + "title": "User Name" } }, { - "name": "memory_id", - "in": "path", - "required": true, + "name": "timeout_seconds", + "in": "query", + "required": false, "schema": { - "type": "string", - "title": "Memory Id" + "type": "number", + "default": 120.0, + "title": "Timeout Seconds" } }, { - "name": "user_id", + "name": "poll_interval", "in": "query", "required": false, "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "User Id" + "type": "number", + "default": 0.5, + "title": "Poll Interval" } } ], @@ -411,9 +324,7 @@ "description": "Successful Response", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/MemoryResponse" - } + "schema": {} } } }, @@ -428,67 +339,32 @@ } } } - }, - "put": { - "summary": "Update a memory", - "description": "Update an existing memory in a MemCube.", - "operationId": "update_memory_memories__mem_cube_id___memory_id__put", - "parameters": [ - { - "name": "mem_cube_id", - "in": "path", - "required": true, - "schema": { - "type": "string", - "title": "Mem Cube Id" - } - }, - { - "name": "memory_id", - "in": "path", - "required": true, - "schema": { - "type": "string", - "title": "Memory Id" - } - }, - { - "name": "user_id", - "in": "query", - "required": false, - "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "User Id" - } - } + } + }, + "/product/chat/complete": { + "post": { + "tags": [ + "Server API" ], + "summary": "Chat with MemOS (Complete Response)", + "description": "Chat with MemOS for a specific user. Returns complete response (non-streaming).\n\nThis endpoint uses the class-based ChatHandler.", + "operationId": "chat_complete_product_chat_complete_post", "requestBody": { - "required": true, "content": { "application/json": { "schema": { - "type": "object", - "additionalProperties": true, - "title": "Updated Memory" + "$ref": "#/components/schemas/APIChatCompleteRequest" } } - } + }, + "required": true }, "responses": { "200": { "description": "Successful Response", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/SimpleResponse" - } + "schema": {} } } }, @@ -503,55 +379,32 @@ } } } - }, - "delete": { - "summary": "Delete a memory", - "description": "Delete a specific memory from a MemCube.", - "operationId": "delete_memory_memories__mem_cube_id___memory_id__delete", - "parameters": [ - { - "name": "mem_cube_id", - "in": "path", - "required": true, - "schema": { - "type": "string", - "title": "Mem Cube Id" - } - }, - { - "name": "memory_id", - "in": "path", - "required": true, - "schema": { - "type": "string", - "title": "Memory Id" + } + }, + "/product/chat/stream": { + "post": { + "tags": [ + "Server API" + ], + "summary": "Chat with MemOS", + "description": "Chat with MemOS for a specific user. Returns SSE stream.\n\nThis endpoint uses the class-based ChatHandler which internally\ncomposes SearchHandler and AddHandler for a clean architecture.", + "operationId": "chat_stream_product_chat_stream_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ChatRequest" + } } }, - { - "name": "user_id", - "in": "query", - "required": false, - "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "User Id" - } - } - ], + "required": true + }, "responses": { "200": { "description": "Successful Response", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/SimpleResponse" - } + "schema": {} } } }, @@ -568,16 +421,19 @@ } } }, - "/search": { + "/product/chat/stream/playground": { "post": { - "summary": "Search memories", - "description": "Search for memories across MemCubes.", - "operationId": "search_memories_search_post", + "tags": [ + "Server API" + ], + "summary": "Chat with MemOS playground", + "description": "Chat with MemOS for a specific user. Returns SSE stream.\n\nThis endpoint uses the class-based ChatHandler which internally\ncomposes SearchHandler and AddHandler for a clean architecture.", + "operationId": "chat_stream_playground_product_chat_stream_playground_post", "requestBody": { "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SearchRequest" + "$ref": "#/components/schemas/ChatPlaygroundRequest" } } }, @@ -588,9 +444,7 @@ "description": "Successful Response", "content": { "application/json": { - "schema": { - "$ref": "#/components/schemas/SearchResponse" - } + "schema": {} } } }, @@ -607,45 +461,73 @@ } } }, - "/memories/{mem_cube_id}": { - "delete": { - "summary": "Delete all memories", - "description": "Delete all memories from a MemCube.", - "operationId": "delete_all_memories_memories__mem_cube_id__delete", - "parameters": [ - { - "name": "mem_cube_id", - "in": "path", - "required": true, - "schema": { - "type": "string", - "title": "Mem Cube Id" + "/product/suggestions": { + "post": { + "tags": [ + "Server API" + ], + "summary": "Get suggestion queries", + "description": "Get suggestion queries for a specific user with language preference.", + "operationId": "get_suggestion_queries_product_suggestions_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuggestionRequest" + } } }, - { - "name": "user_id", - "in": "query", - "required": false, - "schema": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" + "required": true + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SuggestionResponse" } - ], - "title": "User Id" + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } } } + } + } + }, + "/product/get_all": { + "post": { + "tags": [ + "Server API" ], + "summary": "Get all memories for user", + "description": "Get all memories or subgraph for a specific user.\n\nIf search_query is provided, returns a subgraph based on the query.\nOtherwise, returns all memories of the specified type.", + "operationId": "get_all_memories_product_get_all_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetMemoryPlaygroundRequest" + } + } + }, + "required": true + }, "responses": { "200": { "description": "Successful Response", "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/SimpleResponse" + "$ref": "#/components/schemas/MemoryResponse" } } } @@ -663,16 +545,101 @@ } } }, - "/chat": { + "/product/get_memory": { "post": { - "summary": "Chat with MemOS", - "description": "Chat with the MemOS system.", - "operationId": "chat_chat_post", + "tags": [ + "Server API" + ], + "summary": "Get memories for user", + "operationId": "get_memories_product_get_memory_post", "requestBody": { "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChatRequest" + "$ref": "#/components/schemas/GetMemoryRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetMemoryResponse" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/product/delete_memory": { + "post": { + "tags": [ + "Server API" + ], + "summary": "Delete memories for user", + "operationId": "delete_memories_product_delete_memory_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeleteMemoryRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeleteMemoryResponse" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + } + } + } + } + }, + "/product/feedback": { + "post": { + "tags": [ + "Server API" + ], + "summary": "Feedback memories", + "description": "Feedback memories for a specific user.\n\nThis endpoint uses the class-based FeedbackHandler for better code organization.", + "operationId": "feedback_memories_product_feedback_post", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/APIFeedbackRequest" } } }, @@ -684,7 +651,7 @@ "content": { "application/json": { "schema": { - "$ref": "#/components/schemas/ChatResponse" + "$ref": "#/components/schemas/MemoryResponse" } } } @@ -705,9 +672,14 @@ }, "components": { "schemas": { - "ChatRequest": { + "APIADDRequest": { "properties": { "user_id": { + "type": "string", + "title": "User Id", + "description": "User ID" + }, + "session_id": { "anyOf": [ { "type": "string" @@ -716,39 +688,10 @@ "type": "null" } ], - "title": "User Id", - "description": "User ID for the request", - "example": "user123" - }, - "query": { - "type": "string", - "title": "Query", - "description": "Chat query message.", - "example": "What is the latest update?" - } - }, - "type": "object", - "required": [ - "query" - ], - "title": "ChatRequest" - }, - "ChatResponse": { - "properties": { - "code": { - "type": "integer", - "title": "Code", - "description": "Response status code", - "default": 200, - "example": 200 - }, - "message": { - "type": "string", - "title": "Message", - "description": "Response message", - "example": "Operation successful" + "title": "Session Id", + "description": "Session ID. If not provided, a default session will be used." }, - "data": { + "task_id": { "anyOf": [ { "type": "string" @@ -757,301 +700,1967 @@ "type": "null" } ], - "title": "Data", - "description": "Response data" - } - }, - "type": "object", - "required": [ - "message" - ], - "title": "ChatResponse", - "description": "Response model for chat operations." - }, - "ConfigResponse": { - "properties": { - "code": { - "type": "integer", - "title": "Code", - "description": "Response status code", - "default": 200, - "example": 200 + "title": "Task Id", + "description": "Task ID for monitering async tasks" }, - "message": { - "type": "string", - "title": "Message", - "description": "Response message", - "example": "Operation successful" - }, - "data": { - "type": "null", - "title": "Data", - "description": "Response data" - } - }, - "type": "object", - "required": [ - "message" - ], - "title": "ConfigResponse", - "description": "Response model for configuration endpoint." - }, - "CubeShare": { - "properties": { - "user_id": { + "writable_cube_ids": { "anyOf": [ { - "type": "string" + "items": { + "type": "string" + }, + "type": "array" }, { "type": "null" } ], - "title": "User Id", - "description": "User ID for the request", - "example": "user123" - }, - "target_user_id": { - "type": "string", - "title": "Target User Id", - "description": "Target user ID to share with", - "example": "user456" - } - }, - "type": "object", - "required": [ - "target_user_id" - ], - "title": "CubeShare" - }, - "HTTPValidationError": { - "properties": { - "detail": { - "items": { - "$ref": "#/components/schemas/ValidationError" - }, - "type": "array", - "title": "Detail" - } - }, - "type": "object", - "title": "HTTPValidationError" - }, - "LLMConfigFactory": { - "properties": { - "model_schema": { - "type": "string", - "title": "Model Schema", - "description": "Schema for configuration. This value will be automatically set.", - "default": "NOT_SET" - }, - "backend": { - "type": "string", - "title": "Backend", - "description": "Backend for LLM" - }, - "config": { - "additionalProperties": true, - "type": "object", - "title": "Config", - "description": "Configuration for the LLM backend" - } - }, - "additionalProperties": false, - "type": "object", - "required": [ - "backend", - "config" - ], - "title": "LLMConfigFactory", - "description": "Factory class for creating LLM configurations." - }, - "MOSConfig": { - "properties": { - "model_schema": { - "type": "string", - "title": "Model Schema", - "description": "Schema for configuration. This value will be automatically set.", - "default": "NOT_SET" - }, - "user_id": { - "type": "string", - "title": "User Id", - "description": "User ID for the MOS. This is used to distinguish between different users' memories.", - "default": "root" + "title": "Writable Cube Ids", + "description": "List of cube IDs user can write for multi-cube add" }, - "session_id": { + "async_mode": { "type": "string", - "title": "Session Id", - "description": "Session ID for the MOS. This is used to distinguish between different dialogue", - "default": "8dcdbd62-c231-4678-a3ae-0946b7d9ce14" - }, - "chat_model": { - "$ref": "#/components/schemas/LLMConfigFactory", - "description": "LLM configuration for the chat model in the MOS" - }, - "mem_reader": { - "$ref": "#/components/schemas/MemReaderConfigFactory", - "description": "MemReader configuration for the MOS" + "enum": [ + "async", + "sync" + ], + "title": "Async Mode", + "description": "Whether to add memory in async mode. Use 'async' to enqueue background add (non-blocking), or 'sync' to add memories in the current call. Default: 'async'.", + "default": "async" }, - "mem_scheduler": { + "mode": { "anyOf": [ { - "$ref": "#/components/schemas/SchedulerConfigFactory" + "type": "string", + "enum": [ + "fast", + "fine" + ] }, { "type": "null" } ], - "description": "Memory scheduler configuration for managing memory operations" + "title": "Mode", + "description": "(Internal) Add mode used only when async_mode='sync'. If set to 'fast', the handler will use a fast add pipeline. Ignored when async_mode='async'." }, - "user_manager": { - "$ref": "#/components/schemas/UserManagerConfigFactory", - "description": "User manager configuration for database operations" - }, - "max_turns_window": { - "type": "integer", - "title": "Max Turns Window", - "description": "Maximum number of turns to keep in the conversation history", - "default": 15 - }, - "top_k": { - "type": "integer", - "title": "Top K", - "description": "Maximum number of memories to retrieve for each query", - "default": 5 - }, - "enable_textual_memory": { - "type": "boolean", - "title": "Enable Textual Memory", - "description": "Enable textual memory for the MemChat", - "default": true - }, - "enable_activation_memory": { - "type": "boolean", - "title": "Enable Activation Memory", - "description": "Enable activation memory for the MemChat", - "default": false - }, - "enable_parametric_memory": { - "type": "boolean", - "title": "Enable Parametric Memory", - "description": "Enable parametric memory for the MemChat", - "default": false - }, - "enable_preference_memory": { - "type": "boolean", - "title": "Enable Preference Memory", - "description": "Enable preference memory for the MemChat", - "default": false - }, - "enable_mem_scheduler": { - "type": "boolean", - "title": "Enable Mem Scheduler", - "description": "Enable memory scheduler for automated memory management", - "default": false - }, - "PRO_MODE": { - "type": "boolean", - "title": "Pro Mode", - "description": "Enable PRO mode for complex query decomposition", - "default": false - } - }, - "additionalProperties": false, - "type": "object", - "title": "MOSConfig" - }, - "MemCubeRegister": { - "properties": { - "user_id": { + "custom_tags": { "anyOf": [ { - "type": "string" - }, + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Custom Tags", + "description": "Custom tags for this add request, e.g. ['Travel', 'family']. These tags can be used as filters in search." + }, + "info": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Info", + "description": "Additional metadata for the add request. All keys can be used as filters in search. Example: {'agent_id': 'xxxxxx', 'app_id': 'xxxx', 'source_type': 'web', 'source_url': 'https://www.baidu.com', 'source_content': '西湖是杭州最著名的景点'}." + }, + "messages": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/File" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Messages", + "description": "List of messages to store. Supports: - system / user / assistant messages with 'content' and 'chat_time'; - tool messages including: * tool_description (name, description, parameters), * tool_input (call_id, name, argument), * raw tool messages where content is str or list[str], * tool_output with structured output items (input_text / input_image / input_file, etc.). Also supports pure input items when there is no dialog." + }, + "chat_history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Chat History", + "description": "Historical chat messages used internally by algorithms. If None, internal stored history will be used; if provided (even an empty list), this value will be used as-is." + }, + "is_feedback": { + "type": "boolean", + "title": "Is Feedback", + "description": "Whether this request represents user feedback. Default: False.", + "default": false + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "(Deprecated) Target cube ID for this add request (optional for developer API)." + }, + "memory_content": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Memory Content", + "description": "(Deprecated) Plain memory content to store. Prefer using `messages`." + }, + "doc_path": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Doc Path", + "description": "(Deprecated / internal) Path to document to store." + }, + "source": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Source", + "description": "(Deprecated) Simple source tag of the memory. Prefer using `info.source_type` / `info.source_url`." + }, + "operation": { + "anyOf": [ + { + "items": { + "$ref": "#/components/schemas/PermissionDict" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Operation", + "description": "(Internal) Operation definitions for multi-cube write permissions." + } + }, + "type": "object", + "title": "APIADDRequest", + "description": "Request model for creating memories." + }, + "APIChatCompleteRequest": { + "properties": { + "user_id": { + "type": "string", + "title": "User Id", + "description": "User ID" + }, + "query": { + "type": "string", + "title": "Query", + "description": "Chat query message" + }, + "readable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Readable Cube Ids", + "description": "List of cube IDs user can read for multi-cube chat" + }, + "writable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Writable Cube Ids", + "description": "List of cube IDs user can write for multi-cube chat" + }, + "history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "History", + "description": "Chat history" + }, + "mode": { + "$ref": "#/components/schemas/SearchMode", + "description": "search mode: fast, fine, or mixture", + "default": "fast" + }, + "system_prompt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "System Prompt", + "description": "Base system prompt to use for chat" + }, + "top_k": { + "type": "integer", + "title": "Top K", + "description": "Number of results to return", + "default": 10 + }, + "session_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Session Id", + "description": "Session ID for soft-filtering memories" + }, + "include_preference": { + "type": "boolean", + "title": "Include Preference", + "description": "Whether to handle preference memory", + "default": true + }, + "pref_top_k": { + "type": "integer", + "title": "Pref Top K", + "description": "Number of preference results to return", + "default": 6 + }, + "model_name_or_path": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Model Name Or Path", + "description": "Model name to use for chat" + }, + "max_tokens": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Max Tokens", + "description": "Max tokens to generate" + }, + "temperature": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Temperature", + "description": "Temperature for sampling" + }, + "top_p": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Top P", + "description": "Top-p (nucleus) sampling parameter" + }, + "add_message_on_answer": { + "type": "boolean", + "title": "Add Message On Answer", + "description": "Add dialogs to memory after chat", + "default": true + }, + "filter": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Filter", + "description": "\n Filter for the memory, example:\n {\n \"`and` or `or`\": [\n {\"id\": \"uuid-xxx\"},\n {\"created_at\": {\"gt\": \"2024-01-01\"}},\n ]\n }\n " + }, + "internet_search": { + "type": "boolean", + "title": "Internet Search", + "description": "Whether to use internet search", + "default": false + }, + "threshold": { + "type": "number", + "title": "Threshold", + "description": "Threshold for filtering references", + "default": 0.5 + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "Cube ID to use for chat" + }, + "moscube": { + "type": "boolean", + "title": "Moscube", + "description": "(Deprecated) Whether to use legacy MemOSCube pipeline", + "default": false + } + }, + "type": "object", + "required": [ + "user_id", + "query" + ], + "title": "APIChatCompleteRequest", + "description": "Request model for chat operations." + }, + "APIFeedbackRequest": { + "properties": { + "user_id": { + "type": "string", + "title": "User Id", + "description": "User ID" + }, + "session_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Session Id", + "description": "Session ID for soft-filtering memories", + "default": "default_session" + }, + "task_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Task Id", + "description": "Task ID for monitering async tasks" + }, + "history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "History", + "description": "Chat history" + }, + "retrieved_memory_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Retrieved Memory Ids", + "description": "Retrieved memory ids at last turn" + }, + "feedback_content": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Feedback Content", + "description": "Feedback content to process" + }, + "feedback_time": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Feedback Time", + "description": "Feedback time" + }, + "writable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Writable Cube Ids", + "description": "List of cube IDs user can write for multi-cube add" + }, + "async_mode": { + "type": "string", + "enum": [ + "sync", + "async" + ], + "title": "Async Mode", + "description": "feedback mode: sync or async", + "default": "async" + }, + "corrected_answer": { + "type": "boolean", + "title": "Corrected Answer", + "description": "Whether need return corrected answer", + "default": false + }, + "info": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Info", + "description": "Additional metadata for the add request. All keys can be used as filters in search. Example: {'agent_id': 'xxxxxx', 'app_id': 'xxxx', 'source_type': 'web', 'source_url': 'https://www.baidu.com', 'source_content': 'West Lake is the most famous scenic spot in Hangzhou'}." + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "(Deprecated) Single cube ID to search in. Prefer `readable_cube_ids` for multi-cube search." + } + }, + "type": "object", + "required": [ + "user_id", + "history", + "feedback_content" + ], + "title": "APIFeedbackRequest", + "description": "Request model for processing feedback info." + }, + "APISearchRequest": { + "properties": { + "query": { + "type": "string", + "title": "Query", + "description": "User search query" + }, + "user_id": { + "type": "string", + "title": "User Id", + "description": "User ID" + }, + "readable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Readable Cube Ids", + "description": "List of cube IDs that are readable for this request. Required for algorithm-facing API; optional for developer-facing API." + }, + "mode": { + "$ref": "#/components/schemas/SearchMode", + "description": "Search mode: fast, fine, or mixture.", + "default": "fast" + }, + "session_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Session Id", + "description": "Session ID used as a soft signal to prioritize more relevant memories. Only used for weighting, not as a hard filter." + }, + "top_k": { + "type": "integer", + "minimum": 1.0, + "title": "Top K", + "description": "Number of textual memories to retrieve (top-K). Default: 10.", + "default": 10 + }, + "pref_top_k": { + "type": "integer", + "minimum": 0.0, + "title": "Pref Top K", + "description": "Number of preference memories to retrieve (top-K). Default: 6.", + "default": 6 + }, + "include_preference": { + "type": "boolean", + "title": "Include Preference", + "description": "Whether to retrieve preference memories along with general memories. If enabled, the system will automatically recall user preferences relevant to the query. Default: True.", + "default": true + }, + "search_tool_memory": { + "type": "boolean", + "title": "Search Tool Memory", + "description": "Whether to retrieve tool memories along with general memories. If enabled, the system will automatically recall tool memories relevant to the query. Default: True.", + "default": true + }, + "tool_mem_top_k": { + "type": "integer", + "minimum": 0.0, + "title": "Tool Mem Top K", + "description": "Number of tool memories to retrieve (top-K). Default: 6.", + "default": 6 + }, + "filter": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Filter", + "description": "\n Filter for the memory, example:\n {\n \"`and` or `or`\": [\n {\"id\": \"uuid-xxx\"},\n {\"created_at\": {\"gt\": \"2024-01-01\"}},\n ]\n }\n " + }, + "internet_search": { + "type": "boolean", + "title": "Internet Search", + "description": "Whether to enable internet search in addition to memory search. Primarily used by internal algorithms. Default: False.", + "default": false + }, + "threshold": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Threshold", + "description": "Internal similarity threshold for searching plaintext memories. If None, default thresholds will be applied." + }, + "search_memory_type": { + "type": "string", + "title": "Search Memory Type", + "description": "Type of memory to search: All, WorkingMemory, LongTermMemory, UserMemory, OuterMemory, ToolSchemaMemory, ToolTrajectoryMemory", + "default": "All" + }, + "chat_history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Chat History", + "description": "Historical chat messages used internally by algorithms. If None, internal stored history may be used; if provided (even an empty list), this value will be used as-is." + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "(Deprecated) Single cube ID to search in. Prefer `readable_cube_ids` for multi-cube search." + }, + "moscube": { + "type": "boolean", + "title": "Moscube", + "description": "(Deprecated / internal) Whether to use legacy MemOSCube path.", + "default": false + }, + "operation": { + "anyOf": [ + { + "items": { + "$ref": "#/components/schemas/PermissionDict" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Operation", + "description": "(Internal) Operation definitions for multi-cube read permissions." + }, + "source": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Source", + "description": "Source of the search query [plugin will router diff search]" + } + }, + "type": "object", + "required": [ + "query", + "user_id" + ], + "title": "APISearchRequest", + "description": "Request model for searching memories." + }, + "AllStatusResponse": { + "properties": { + "code": { + "type": "integer", + "title": "Code", + "description": "Response status code", + "default": 200 + }, + "message": { + "type": "string", + "title": "Message", + "default": "Scheduler status summary retrieved successfully" + }, + "data": { + "anyOf": [ + { + "$ref": "#/components/schemas/AllStatusResponseData" + }, + { + "type": "null" + } + ], + "description": "Response data" + } + }, + "type": "object", + "title": "AllStatusResponse", + "description": "Response model for full scheduler status operations." + }, + "AllStatusResponseData": { + "properties": { + "scheduler_summary": { + "$ref": "#/components/schemas/TaskSummary", + "description": "Aggregated status for scheduler-managed tasks" + }, + "all_tasks_summary": { + "$ref": "#/components/schemas/TaskSummary", + "description": "Aggregated status for all tracked tasks" + } + }, + "type": "object", + "required": [ + "scheduler_summary", + "all_tasks_summary" + ], + "title": "AllStatusResponseData", + "description": "Aggregated scheduler status metrics." + }, + "Audio": { + "properties": { + "id": { + "type": "string", + "title": "Id" + } + }, + "type": "object", + "required": [ + "id" + ], + "title": "Audio" + }, + "ChatCompletionAssistantMessageParam": { + "properties": { + "role": { + "type": "string", + "const": "assistant", + "title": "Role" + }, + "audio": { + "anyOf": [ + { + "$ref": "#/components/schemas/Audio" + }, + { + "type": "null" + } + ] + }, + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartRefusalParam" + } + ] + }, + "type": "array" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartRefusalParam" + }, + { + "type": "null" + } + ], + "title": "Content" + }, + "refusal": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Refusal" + }, + "tool_calls": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionMessageFunctionToolCallParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionMessageCustomToolCallParam" + } + ] + }, + "type": "array" + }, + { + "$ref": "#/components/schemas/ChatCompletionMessageFunctionToolCallParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionMessageCustomToolCallParam" + } + ], + "title": "Tool Calls" + }, + "chat_time": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Chat Time" + }, + "message_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Message Id" + } + }, + "type": "object", + "required": [ + "role" + ], + "title": "ChatCompletionAssistantMessageParam" + }, + "ChatCompletionContentPartImageParam": { + "properties": { + "image_url": { + "$ref": "#/components/schemas/ImageURL" + }, + "type": { + "type": "string", + "const": "image_url", + "title": "Type" + } + }, + "type": "object", + "required": [ + "image_url", + "type" + ], + "title": "ChatCompletionContentPartImageParam" + }, + "ChatCompletionContentPartInputAudioParam": { + "properties": { + "input_audio": { + "$ref": "#/components/schemas/InputAudio" + }, + "type": { + "type": "string", + "const": "input_audio", + "title": "Type" + } + }, + "type": "object", + "required": [ + "input_audio", + "type" + ], + "title": "ChatCompletionContentPartInputAudioParam" + }, + "ChatCompletionContentPartRefusalParam": { + "properties": { + "refusal": { + "type": "string", + "title": "Refusal" + }, + "type": { + "type": "string", + "const": "refusal", + "title": "Type" + } + }, + "type": "object", + "required": [ + "refusal", + "type" + ], + "title": "ChatCompletionContentPartRefusalParam" + }, + "ChatCompletionContentPartTextParam": { + "properties": { + "text": { + "type": "string", + "title": "Text" + }, + "type": { + "type": "string", + "const": "text", + "title": "Type" + } + }, + "type": "object", + "required": [ + "text", + "type" + ], + "title": "ChatCompletionContentPartTextParam" + }, + "ChatCompletionMessageCustomToolCallParam": { + "properties": { + "id": { + "type": "string", + "title": "Id" + }, + "custom": { + "$ref": "#/components/schemas/Custom" + }, + "type": { + "type": "string", + "const": "custom", + "title": "Type" + } + }, + "type": "object", + "required": [ + "id", + "custom", + "type" + ], + "title": "ChatCompletionMessageCustomToolCallParam" + }, + "ChatCompletionMessageFunctionToolCallParam": { + "properties": { + "id": { + "type": "string", + "title": "Id" + }, + "function": { + "$ref": "#/components/schemas/Function" + }, + "type": { + "type": "string", + "const": "function", + "title": "Type" + } + }, + "type": "object", + "required": [ + "id", + "function", + "type" + ], + "title": "ChatCompletionMessageFunctionToolCallParam" + }, + "ChatCompletionSystemMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + "type": "array" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + } + ], + "title": "Content" + }, + "role": { + "type": "string", + "const": "system", + "title": "Role" + }, + "name": { + "type": "string", + "title": "Name" + }, + "chat_time": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Chat Time" + }, + "message_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Message Id" + } + }, + "type": "object", + "required": [ + "content", + "role" + ], + "title": "ChatCompletionSystemMessageParam" + }, + "ChatCompletionToolMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/components/schemas/File" + } + ] + }, + "type": "array" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/components/schemas/File" + } + ], + "title": "Content" + }, + "role": { + "type": "string", + "const": "tool", + "title": "Role" + }, + "tool_call_id": { + "type": "string", + "title": "Tool Call Id" + }, + "chat_time": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Chat Time" + }, + "message_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Message Id" + } + }, + "type": "object", + "required": [ + "content", + "role", + "tool_call_id" + ], + "title": "ChatCompletionToolMessageParam" + }, + "ChatCompletionUserMessageParam": { + "properties": { + "content": { + "anyOf": [ + { + "type": "string" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/components/schemas/File" + } + ] + }, + "type": "array" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartImageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionContentPartInputAudioParam" + }, + { + "$ref": "#/components/schemas/File" + } + ], + "title": "Content" + }, + "role": { + "type": "string", + "const": "user", + "title": "Role" + }, + "name": { + "type": "string", + "title": "Name" + }, + "chat_time": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Chat Time" + }, + "message_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Message Id" + } + }, + "type": "object", + "required": [ + "content", + "role" + ], + "title": "ChatCompletionUserMessageParam" + }, + "ChatPlaygroundRequest": { + "properties": { + "user_id": { + "type": "string", + "title": "User Id", + "description": "User ID" + }, + "query": { + "type": "string", + "title": "Query", + "description": "Chat query message" + }, + "readable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Readable Cube Ids", + "description": "List of cube IDs user can read for multi-cube chat" + }, + "writable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Writable Cube Ids", + "description": "List of cube IDs user can write for multi-cube chat" + }, + "history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "History", + "description": "Chat history" + }, + "mode": { + "$ref": "#/components/schemas/SearchMode", + "description": "search mode: fast, fine, or mixture", + "default": "fast" + }, + "system_prompt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "System Prompt", + "description": "Base system prompt to use for chat" + }, + "top_k": { + "type": "integer", + "title": "Top K", + "description": "Number of results to return", + "default": 10 + }, + "session_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Session Id", + "description": "Session ID for soft-filtering memories" + }, + "include_preference": { + "type": "boolean", + "title": "Include Preference", + "description": "Whether to handle preference memory", + "default": true + }, + "pref_top_k": { + "type": "integer", + "title": "Pref Top K", + "description": "Number of preference results to return", + "default": 6 + }, + "model_name_or_path": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Model Name Or Path", + "description": "Model name to use for chat" + }, + "max_tokens": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Max Tokens", + "description": "Max tokens to generate" + }, + "temperature": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Temperature", + "description": "Temperature for sampling" + }, + "top_p": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Top P", + "description": "Top-p (nucleus) sampling parameter" + }, + "add_message_on_answer": { + "type": "boolean", + "title": "Add Message On Answer", + "description": "Add dialogs to memory after chat", + "default": true + }, + "filter": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Filter", + "description": "\n Filter for the memory, example:\n {\n \"`and` or `or`\": [\n {\"id\": \"uuid-xxx\"},\n {\"created_at\": {\"gt\": \"2024-01-01\"}},\n ]\n }\n " + }, + "internet_search": { + "type": "boolean", + "title": "Internet Search", + "description": "Whether to use internet search", + "default": false + }, + "threshold": { + "type": "number", + "title": "Threshold", + "description": "Threshold for filtering references", + "default": 0.5 + }, + "moscube": { + "type": "boolean", + "title": "Moscube", + "description": "(Deprecated) Whether to use legacy MemOSCube pipeline.", + "default": false + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "(Deprecated) Single cube ID to use for chat. Prefer `readable_cube_ids` / `writable_cube_ids` for multi-cube chat." + }, + "beginner_guide_step": { + "anyOf": [ + { + "type": "string" + }, { "type": "null" } ], + "title": "Beginner Guide Step", + "description": "Whether to use beginner guide, option: [first, second]" + } + }, + "type": "object", + "required": [ + "user_id", + "query" + ], + "title": "ChatPlaygroundRequest", + "description": "Request model for chat operations in playground." + }, + "ChatRequest": { + "properties": { + "user_id": { + "type": "string", "title": "User Id", - "description": "User ID for the request", - "example": "user123" + "description": "User ID" + }, + "query": { + "type": "string", + "title": "Query", + "description": "Chat query message" + }, + "readable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Readable Cube Ids", + "description": "List of cube IDs user can read for multi-cube chat" + }, + "writable_cube_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Writable Cube Ids", + "description": "List of cube IDs user can write for multi-cube chat" + }, + "history": { + "anyOf": [ + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "History", + "description": "Chat history" + }, + "mode": { + "$ref": "#/components/schemas/SearchMode", + "description": "search mode: fast, fine, or mixture", + "default": "fast" + }, + "system_prompt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "System Prompt", + "description": "Base system prompt to use for chat" + }, + "top_k": { + "type": "integer", + "title": "Top K", + "description": "Number of results to return", + "default": 10 + }, + "session_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Session Id", + "description": "Session ID for soft-filtering memories" + }, + "include_preference": { + "type": "boolean", + "title": "Include Preference", + "description": "Whether to handle preference memory", + "default": true + }, + "pref_top_k": { + "type": "integer", + "title": "Pref Top K", + "description": "Number of preference results to return", + "default": 6 + }, + "model_name_or_path": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Model Name Or Path", + "description": "Model name to use for chat" + }, + "max_tokens": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": "Max Tokens", + "description": "Max tokens to generate" + }, + "temperature": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Temperature", + "description": "Temperature for sampling" + }, + "top_p": { + "anyOf": [ + { + "type": "number" + }, + { + "type": "null" + } + ], + "title": "Top P", + "description": "Top-p (nucleus) sampling parameter" + }, + "add_message_on_answer": { + "type": "boolean", + "title": "Add Message On Answer", + "description": "Add dialogs to memory after chat", + "default": true + }, + "filter": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Filter", + "description": "\n Filter for the memory, example:\n {\n \"`and` or `or`\": [\n {\"id\": \"uuid-xxx\"},\n {\"created_at\": {\"gt\": \"2024-01-01\"}},\n ]\n }\n " + }, + "internet_search": { + "type": "boolean", + "title": "Internet Search", + "description": "Whether to use internet search", + "default": false + }, + "threshold": { + "type": "number", + "title": "Threshold", + "description": "Threshold for filtering references", + "default": 0.5 + }, + "moscube": { + "type": "boolean", + "title": "Moscube", + "description": "(Deprecated) Whether to use legacy MemOSCube pipeline.", + "default": false + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "(Deprecated) Single cube ID to use for chat. Prefer `readable_cube_ids` / `writable_cube_ids` for multi-cube chat." + } + }, + "type": "object", + "required": [ + "user_id", + "query" + ], + "title": "ChatRequest", + "description": "Request model for chat operations.\n\nThis model is used as the algorithm-facing chat interface, while also\nremaining backward compatible with older developer-facing APIs." + }, + "Custom": { + "properties": { + "input": { + "type": "string", + "title": "Input" + }, + "name": { + "type": "string", + "title": "Name" + } + }, + "type": "object", + "required": [ + "input", + "name" + ], + "title": "Custom" + }, + "DeleteMemoryRequest": { + "properties": { + "writable_cube_ids": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Writable Cube Ids", + "description": "Writable cube IDs" + }, + "memory_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "Memory Ids", + "description": "Memory IDs" + }, + "file_ids": { + "anyOf": [ + { + "items": { + "type": "string" + }, + "type": "array" + }, + { + "type": "null" + } + ], + "title": "File Ids", + "description": "File IDs" + }, + "filter": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Filter", + "description": "Filter for the memory" + } + }, + "type": "object", + "required": [ + "writable_cube_ids" + ], + "title": "DeleteMemoryRequest", + "description": "Request model for deleting memories." + }, + "DeleteMemoryResponse": { + "properties": { + "code": { + "type": "integer", + "title": "Code", + "description": "Response status code", + "default": 200 + }, + "message": { + "type": "string", + "title": "Message", + "description": "Response message" + }, + "data": { + "anyOf": [ + { + "additionalProperties": true, + "type": "object" + }, + { + "type": "null" + } + ], + "title": "Data", + "description": "Response data" + } + }, + "type": "object", + "required": [ + "message" + ], + "title": "DeleteMemoryResponse", + "description": "Response model for deleting memories." + }, + "File": { + "properties": { + "file": { + "$ref": "#/components/schemas/FileFile" }, - "mem_cube_name_or_path": { + "type": { "type": "string", - "title": "Mem Cube Name Or Path", - "description": "Name or path of the MemCube to register.", - "example": "/path/to/cube" - }, - "mem_cube_id": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Mem Cube Id", - "description": "ID for the MemCube", - "example": "cube123" + "const": "file", + "title": "Type" } }, "type": "object", "required": [ - "mem_cube_name_or_path" + "file", + "type" ], - "title": "MemCubeRegister" + "title": "File" + }, + "FileFile": { + "properties": { + "file_data": { + "type": "string", + "title": "File Data" + }, + "file_id": { + "type": "string", + "title": "File Id" + }, + "filename": { + "type": "string", + "title": "Filename" + } + }, + "type": "object", + "title": "FileFile" }, - "MemReaderConfigFactory": { + "Function": { "properties": { - "model_schema": { + "arguments": { "type": "string", - "title": "Model Schema", - "description": "Schema for configuration. This value will be automatically set.", - "default": "NOT_SET" + "title": "Arguments" }, - "backend": { + "name": { "type": "string", - "title": "Backend", - "description": "Backend for MemReader" - }, - "config": { - "additionalProperties": true, - "type": "object", - "title": "Config", - "description": "Configuration for the MemReader backend" + "title": "Name" } }, - "additionalProperties": false, "type": "object", "required": [ - "backend", - "config" + "arguments", + "name" ], - "title": "MemReaderConfigFactory", - "description": "Factory class for creating MemReader configurations." + "title": "Function" }, - "MemoryCreate": { + "GetMemoryPlaygroundRequest": { "properties": { "user_id": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], + "type": "string", "title": "User Id", - "description": "User ID for the request", - "example": "user123" + "description": "User ID" }, - "messages": { + "memory_type": { + "type": "string", + "enum": [ + "text_mem", + "act_mem", + "param_mem", + "para_mem" + ], + "title": "Memory Type", + "description": "Memory type" + }, + "mem_cube_ids": { "anyOf": [ { "items": { - "$ref": "#/components/schemas/Message" + "type": "string" }, "type": "array" }, @@ -1059,16 +2668,10 @@ "type": "null" } ], - "title": "Messages", - "description": "List of messages to store.", - "example": [ - { - "content": "Hello", - "role": "user" - } - ] + "title": "Mem Cube Ids", + "description": "Cube IDs" }, - "mem_cube_id": { + "search_query": { "anyOf": [ { "type": "string" @@ -1077,11 +2680,26 @@ "type": "null" } ], + "title": "Search Query", + "description": "Search query" + } + }, + "type": "object", + "required": [ + "user_id", + "memory_type" + ], + "title": "GetMemoryPlaygroundRequest", + "description": "Request model for getting memories." + }, + "GetMemoryRequest": { + "properties": { + "mem_cube_id": { + "type": "string", "title": "Mem Cube Id", - "description": "ID of the memory cube", - "example": "cube123" + "description": "Cube ID" }, - "memory_content": { + "user_id": { "anyOf": [ { "type": "string" @@ -1090,41 +2708,35 @@ "type": "null" } ], - "title": "Memory Content", - "description": "Content to store as memory", - "example": "This is a memory content" + "title": "User Id", + "description": "User ID" }, - "doc_path": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Doc Path", - "description": "Path to document to store", - "example": "/path/to/document.txt" + "include_preference": { + "type": "boolean", + "title": "Include Preference", + "description": "Whether to handle preference memory", + "default": true } }, "type": "object", - "title": "MemoryCreate" + "required": [ + "mem_cube_id" + ], + "title": "GetMemoryRequest", + "description": "Request model for getting memories." }, - "MemoryResponse": { + "GetMemoryResponse": { "properties": { "code": { "type": "integer", "title": "Code", "description": "Response status code", - "default": 200, - "example": 200 + "default": 200 }, "message": { "type": "string", "title": "Message", - "description": "Response message", - "example": "Operation successful" + "description": "Response message" }, "data": { "anyOf": [ @@ -1144,106 +2756,133 @@ "required": [ "message" ], - "title": "MemoryResponse", - "description": "Response model for memory operations." + "title": "GetMemoryResponse", + "description": "Response model for getting memories." }, - "Message": { + "HTTPValidationError": { "properties": { - "role": { + "detail": { + "items": { + "$ref": "#/components/schemas/ValidationError" + }, + "type": "array", + "title": "Detail" + } + }, + "type": "object", + "title": "HTTPValidationError" + }, + "ImageURL": { + "properties": { + "url": { "type": "string", - "title": "Role", - "description": "Role of the message (user or assistant).", - "example": "user" + "title": "Url" }, - "content": { + "detail": { "type": "string", - "title": "Content", - "description": "Message content.", - "example": "Hello, how can I help you?" + "enum": [ + "auto", + "low", + "high" + ], + "title": "Detail" } }, "type": "object", "required": [ - "role", - "content" + "url" ], - "title": "Message" + "title": "ImageURL" }, - "SchedulerConfigFactory": { + "InputAudio": { "properties": { - "model_schema": { + "data": { "type": "string", - "title": "Model Schema", - "description": "Schema for configuration. This value will be automatically set.", - "default": "NOT_SET" + "title": "Data" }, - "backend": { + "format": { "type": "string", - "title": "Backend", - "description": "Backend for scheduler" - }, - "config": { - "additionalProperties": true, - "type": "object", - "title": "Config", - "description": "Configuration for the scheduler backend" + "enum": [ + "wav", + "mp3" + ], + "title": "Format" } }, - "additionalProperties": false, "type": "object", "required": [ - "backend", - "config" + "data", + "format" ], - "title": "SchedulerConfigFactory", - "description": "Factory class for creating scheduler configurations." + "title": "InputAudio" }, - "SearchRequest": { + "MemoryResponse": { "properties": { - "user_id": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "User Id", - "description": "User ID for the request", - "example": "user123" + "code": { + "type": "integer", + "title": "Code", + "description": "Response status code", + "default": 200 }, - "query": { + "message": { "type": "string", - "title": "Query", - "description": "Search query.", - "example": "How to implement a feature?" + "title": "Message", + "description": "Response message" }, - "install_cube_ids": { + "data": { "anyOf": [ { - "items": { - "type": "string" - }, + "items": {}, "type": "array" }, { "type": "null" } ], - "title": "Install Cube Ids", - "description": "List of cube IDs to search in", - "example": [ - "cube123", - "cube456" - ] + "title": "Data", + "description": "Response data" } }, "type": "object", "required": [ - "query" + "message" + ], + "title": "MemoryResponse", + "description": "Response model for memory operations." + }, + "PermissionDict": { + "properties": { + "permissions": { + "items": { + "type": "string", + "enum": [ + "read", + "write", + "delete", + "execute" + ] + }, + "type": "array", + "title": "Permissions" + }, + "mem_cube_id": { + "type": "string", + "title": "Mem Cube Id" + } + }, + "type": "object", + "title": "PermissionDict", + "description": "Typed dictionary for chat message dictionaries." + }, + "SearchMode": { + "type": "string", + "enum": [ + "fast", + "fine", + "mixture" ], - "title": "SearchRequest" + "title": "SearchMode", + "description": "Enumeration for search modes." }, "SearchResponse": { "properties": { @@ -1251,14 +2890,12 @@ "type": "integer", "title": "Code", "description": "Response status code", - "default": 200, - "example": 200 + "default": 200 }, "message": { "type": "string", "title": "Message", - "description": "Response message", - "example": "Operation successful" + "description": "Response message" }, "data": { "anyOf": [ @@ -1281,89 +2918,165 @@ "title": "SearchResponse", "description": "Response model for search operations." }, - "SimpleResponse": { + "StatusResponse": { "properties": { "code": { "type": "integer", "title": "Code", "description": "Response status code", - "default": 200, - "example": 200 + "default": 200 }, "message": { "type": "string", "title": "Message", - "description": "Response message", - "example": "Operation successful" + "default": "Memory get status successfully" }, "data": { - "type": "null", + "anyOf": [ + { + "items": { + "$ref": "#/components/schemas/StatusResponseItem" + }, + "type": "array" + }, + { + "type": "null" + } + ], "title": "Data", "description": "Response data" } }, "type": "object", + "title": "StatusResponse", + "description": "Response model for scheduler status operations." + }, + "StatusResponseItem": { + "properties": { + "task_id": { + "type": "string", + "title": "Task Id", + "description": "The ID of the task" + }, + "status": { + "type": "string", + "enum": [ + "in_progress", + "completed", + "waiting", + "failed", + "cancelled" + ], + "title": "Status", + "description": "The current status of the task" + } + }, + "type": "object", "required": [ - "message" + "task_id", + "status" ], - "title": "SimpleResponse", - "description": "Simple response model for operations without data return." + "title": "StatusResponseItem", + "description": "Individual task status item." }, - "UserCreate": { + "SuggestionRequest": { "properties": { "user_id": { "type": "string", "title": "User Id", - "description": "User ID", - "example": "user123" + "description": "User ID" }, - "user_name": { + "mem_cube_id": { + "type": "string", + "title": "Mem Cube Id", + "description": "Cube ID" + }, + "language": { + "type": "string", + "enum": [ + "zh", + "en" + ], + "title": "Language", + "description": "Language for suggestions", + "default": "zh" + }, + "message": { "anyOf": [ { "type": "string" }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionSystemMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionUserMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionAssistantMessageParam" + }, + { + "$ref": "#/components/schemas/ChatCompletionToolMessageParam" + } + ] + }, + "type": "array" + }, + { + "items": { + "anyOf": [ + { + "$ref": "#/components/schemas/ChatCompletionContentPartTextParam" + }, + { + "$ref": "#/components/schemas/File" + } + ] + }, + "type": "array" + }, { "type": "null" } ], - "title": "User Name", - "description": "Name of the user", - "example": "john_doe" - }, - "role": { - "type": "string", - "title": "Role", - "description": "Role of the user", - "default": "user", - "example": "user" + "title": "Message", + "description": "List of messages to store." } }, "type": "object", "required": [ - "user_id" + "user_id", + "mem_cube_id" ], - "title": "UserCreate" + "title": "SuggestionRequest", + "description": "Request model for getting suggestion queries." }, - "UserListResponse": { + "SuggestionResponse": { "properties": { "code": { "type": "integer", "title": "Code", "description": "Response status code", - "default": 200, - "example": 200 + "default": 200 }, "message": { "type": "string", "title": "Message", - "description": "Response message", - "example": "Operation successful" + "description": "Response message" }, "data": { "anyOf": [ { - "items": {}, - "type": "array" + "additionalProperties": { + "items": { + "type": "string" + }, + "type": "array" + }, + "type": "object" }, { "type": "null" @@ -1377,63 +3090,170 @@ "required": [ "message" ], - "title": "UserListResponse", - "description": "Response model for user list operations." + "title": "SuggestionResponse", + "description": "Response model for suggestion operations." }, - "UserManagerConfigFactory": { + "TaskQueueData": { "properties": { - "backend": { + "user_id": { "type": "string", - "title": "Backend", - "description": "Backend for user manager", - "default": "sqlite" - }, - "config": { - "additionalProperties": true, - "type": "object", - "title": "Config", - "description": "Configuration for the user manager backend" + "title": "User Id", + "description": "User ID the query is scoped to" + }, + "user_name": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "User Name", + "description": "User name if available" + }, + "mem_cube_id": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Mem Cube Id", + "description": "MemCube ID if a single cube is targeted; otherwise None" + }, + "stream_keys": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Stream Keys", + "description": "Matched Redis stream keys for this user" + }, + "users_count": { + "type": "integer", + "title": "Users Count", + "description": "Distinct users currently present in queue streams" + }, + "pending_tasks_count": { + "type": "integer", + "title": "Pending Tasks Count", + "description": "Count of pending (delivered, not acked) tasks" + }, + "remaining_tasks_count": { + "type": "integer", + "title": "Remaining Tasks Count", + "description": "Count of enqueued tasks (xlen)" + }, + "pending_tasks_detail": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Pending Tasks Detail", + "description": "Per-stream pending counts, formatted as '{stream_key}:{count}'" + }, + "remaining_tasks_detail": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Remaining Tasks Detail", + "description": "Per-stream remaining counts, formatted as '{stream_key}:{count}'" } }, "type": "object", - "title": "UserManagerConfigFactory", - "description": "Factory for user manager configurations." + "required": [ + "user_id", + "stream_keys", + "users_count", + "pending_tasks_count", + "remaining_tasks_count", + "pending_tasks_detail", + "remaining_tasks_detail" + ], + "title": "TaskQueueData", + "description": "Queue-level metrics for scheduler tasks." }, - "UserResponse": { + "TaskQueueResponse": { "properties": { "code": { "type": "integer", "title": "Code", "description": "Response status code", - "default": 200, - "example": 200 + "default": 200 }, "message": { "type": "string", "title": "Message", - "description": "Response message", - "example": "Operation successful" + "default": "Scheduler task queue status retrieved successfully" }, "data": { "anyOf": [ { - "additionalProperties": true, - "type": "object" + "$ref": "#/components/schemas/TaskQueueData" }, { "type": "null" } ], - "title": "Data", "description": "Response data" } }, "type": "object", - "required": [ - "message" - ], - "title": "UserResponse", - "description": "Response model for user operations." + "title": "TaskQueueResponse", + "description": "Response model for scheduler task queue status." + }, + "TaskSummary": { + "properties": { + "waiting": { + "type": "integer", + "title": "Waiting", + "description": "Number of tasks waiting to run", + "default": 0 + }, + "in_progress": { + "type": "integer", + "title": "In Progress", + "description": "Number of tasks currently running", + "default": 0 + }, + "pending": { + "type": "integer", + "title": "Pending", + "description": "Number of tasks fetched by workers but not yet acknowledged", + "default": 0 + }, + "completed": { + "type": "integer", + "title": "Completed", + "description": "Number of tasks completed", + "default": 0 + }, + "failed": { + "type": "integer", + "title": "Failed", + "description": "Number of tasks failed", + "default": 0 + }, + "cancelled": { + "type": "integer", + "title": "Cancelled", + "description": "Number of tasks cancelled", + "default": 0 + }, + "total": { + "type": "integer", + "title": "Total", + "description": "Total number of tasks counted", + "default": 0 + } + }, + "type": "object", + "title": "TaskSummary", + "description": "Aggregated counts of tasks by status." }, "ValidationError": { "properties": { diff --git a/src/memos/cli.py b/src/memos/cli.py index fb3475ff3..568d52794 100644 --- a/src/memos/cli.py +++ b/src/memos/cli.py @@ -13,7 +13,13 @@ def export_openapi(output: str) -> bool: """Export OpenAPI schema to JSON file.""" - from memos.api.start_api import app + from fastapi import FastAPI + + from memos.api.routers.server_router import router + + # Create a temporary FastAPI app to generate OpenAPI schema from router + app = FastAPI(title="MemOS API", version="1.0.0") + app.include_router(router) # Create directory if it doesn't exist if os.path.dirname(output): diff --git a/src/memos/llms/openai.py b/src/memos/llms/openai.py index ea488329d..a4e3308c6 100644 --- a/src/memos/llms/openai.py +++ b/src/memos/llms/openai.py @@ -1,4 +1,5 @@ import json +import time from collections.abc import Generator @@ -89,10 +90,29 @@ def generate_stream(self, messages: MessageList, **kwargs) -> Generator[str, Non response = self.client.chat.completions.create(**request_body) reasoning_started = False + first_token_time = None + start_time = time.perf_counter() for chunk in response: delta = chunk.choices[0].delta + # Calculate TTFT on first token + if first_token_time is None: + first_token_time = time.perf_counter() + ttft_ms = (first_token_time - start_time) * 1000.0 + + # 尝试从响应中获取实际模型信息 + actual_model = getattr(chunk, "model", None) or self.config.model_name_or_path + requested_model = self.config.model_name_or_path + + # Print TTFT info - 显示请求模型和实际模型(如果不一致) + if actual_model != requested_model: + logger.info( + f"TTFT: {ttft_ms:.2f}ms | Requested: {requested_model} | Actual: {actual_model}" + ) + else: + logger.info(f"TTFT: {ttft_ms:.2f}ms | {requested_model}") + # Support for custom 'reasoning_content' (if present in OpenAI-compatible models like Qwen, DeepSeek) if hasattr(delta, "reasoning_content") and delta.reasoning_content: if not reasoning_started and not self.config.remove_think_prefix: diff --git a/src/memos/utils.py b/src/memos/utils.py index 4f2666efd..d9e4ffc85 100644 --- a/src/memos/utils.py +++ b/src/memos/utils.py @@ -24,6 +24,7 @@ def timed_with_status( - log_extra_args: - can be a dict: fixed contextual fields that are always attached to logs; - or a callable: like `fn(*args, **kwargs) -> dict`, used to dynamically generate contextual fields at runtime. + - target_models: list of target models to filter performance tracking """ if isinstance(log_args, str): @@ -54,6 +55,7 @@ def wrapper(*args, **kwargs): return result finally: elapsed_ms = (time.perf_counter() - start) * 1000.0 + total_time = elapsed_ms / 1000.0 # Convert to seconds ctx_parts = [] # 1) Collect parameters from kwargs by name @@ -85,12 +87,32 @@ def wrapper(*args, **kwargs): f", error_type: {exc_type.__name__}, error_message: {exc_message}" ) - msg = ( - f"[TIMER_WITH_STATUS] {log_prefix or fn.__name__} " - f"took {elapsed_ms:.0f} ms{status_info}, args: {ctx_str}" - ) + # Enhanced logging with content metrics for LLM calls + if success_flag and result: + # Calculate content metrics + content_length = len(result) if isinstance(result, str) else 0 + speed = content_length / total_time if total_time > 0 else 0 + + # Get model name from self.config + self = args[0] if args else None + model_name = ( + getattr(self, "config", {}).get("model_name_or_path", "unknown") + if self + else "unknown" + ) - logger.info(msg) + # Console output for target models with performance metrics + logger.info( + f"{model_name}: {log_prefix or fn.__name__} finished | Total time: {total_time:.2f}s | Speed: {speed:.2f} chars/s | Length: {content_length}" + ) + elif ( + success_flag + ): # Standard logging for non-target models or when not tracking metrics + msg = ( + f"[TIMER_WITH_STATUS] {log_prefix or fn.__name__} " + f"took {elapsed_ms:.0f} ms{status_info}, args: {ctx_str}" + ) + logger.info(msg) return wrapper