From f32034e83e2aed71943ee9d095d4e5fe467c1121 Mon Sep 17 00:00:00 2001 From: Wang Qi Date: Wed, 6 May 2026 17:19:22 +0800 Subject: [PATCH] Refactor: completion -> completions (#14584) ### What problem does this PR solve? Keep only /completions, deprecated /completion ### Type of change - [x] Refactoring --- admin/client/ragflow_client.py | 6 +++--- api/apps/backward_compat.py | 6 +++--- api/apps/restful_apis/agent_api.py | 1 + api/apps/restful_apis/search_api.py | 1 + api/apps/services/canvas_replica_service.py | 2 +- docs/references/http_api_reference.md | 20 +++++++++---------- sdk/python/ragflow_sdk/modules/session.py | 2 +- test/testcases/test_http_api/common.py | 2 +- ...test_create_session_with_chat_assistant.py | 2 +- web/src/utils/api.ts | 4 ++-- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/admin/client/ragflow_client.py b/admin/client/ragflow_client.py index 084057bf8..148af4b45 100644 --- a/admin/client/ragflow_client.py +++ b/admin/client/ragflow_client.py @@ -1215,12 +1215,12 @@ class RAGFlowClient: # Prepare payload for completion API # Note: stream parameter is not sent, server defaults to stream=True payload = { - "conversation_id": session_id, + "session_id": session_id, "messages": [{"role": "user", "content": message}] } - response = self.http_client.request("POST", "/conversation/completion", json_body=payload, - use_api_base=False, auth_kind="web", stream=True) + response = self.http_client.request("POST", "/chat/completions", json_body=payload, + use_api_base=True, auth_kind="web", stream=True) if response.status_code != 200: print(f"Fail to chat on session, status code: {response.status_code}") diff --git a/api/apps/backward_compat.py b/api/apps/backward_compat.py index 63739d805..6c2b4ee12 100644 --- a/api/apps/backward_compat.py +++ b/api/apps/backward_compat.py @@ -403,14 +403,14 @@ async def deprecated_file_upload_info(): @add_tenant_id_to_kwargs async def deprecated_agent_completions(agent_id, tenant_id=None): """ - Deprecated: Use POST /api/v1/agents/chat/completion instead. + Deprecated: Use POST /api/v1/agents/chat/completions instead. Old path: POST /api/v1/agents/{agent_id}/completions - New path: POST /api/v1/agents/chat/completion + New path: POST /api/v1/agents/chat/completions """ logging.warning( "API endpoint /api/v1/agents/%s/completions is deprecated. " - "Please use /api/v1/agents/chat/completion instead.", + "Please use /api/v1/agents/chat/completions instead.", agent_id, ) return await agent_api.agent_chat_completion(tenant_id=tenant_id, agent_id=agent_id) diff --git a/api/apps/restful_apis/agent_api.py b/api/apps/restful_apis/agent_api.py index 35e577f32..ffe8e805e 100644 --- a/api/apps/restful_apis/agent_api.py +++ b/api/apps/restful_apis/agent_api.py @@ -846,6 +846,7 @@ async def test_db_connection(): @manager.route("/agents/chat/completion", methods=["POST"]) # noqa: F821 +@manager.route("/agents/chat/completions", methods=["POST"]) # noqa: F821 @login_required @add_tenant_id_to_kwargs async def agent_chat_completion(tenant_id, agent_id=None): diff --git a/api/apps/restful_apis/search_api.py b/api/apps/restful_apis/search_api.py index dfd3e7ed6..c56d0ff83 100644 --- a/api/apps/restful_apis/search_api.py +++ b/api/apps/restful_apis/search_api.py @@ -174,6 +174,7 @@ def delete_search(search_id): @manager.route("/searches//completion", methods=["POST"]) # noqa: F821 +@manager.route("/searches//completions", methods=["POST"]) # noqa: F821 @login_required @validate_request("question") async def completion(search_id): diff --git a/api/apps/services/canvas_replica_service.py b/api/apps/services/canvas_replica_service.py index a2aa56b6f..17b6c99cb 100644 --- a/api/apps/services/canvas_replica_service.py +++ b/api/apps/services/canvas_replica_service.py @@ -160,7 +160,7 @@ class CanvasReplicaService: @classmethod def load_for_run(cls, canvas_id: str, tenant_id: str, runtime_user_id: str): - """Load current runtime replica used by /completion.""" + """Load current runtime replica used by /completions.""" replica_key = cls._replica_key(canvas_id, str(tenant_id), str(runtime_user_id)) return cls._read_payload(replica_key) diff --git a/docs/references/http_api_reference.md b/docs/references/http_api_reference.md index 5390f1a7e..8c2eba3a4 100644 --- a/docs/references/http_api_reference.md +++ b/docs/references/http_api_reference.md @@ -4487,13 +4487,13 @@ Asks a specified agent a question to start an AI-powered conversation. Uses a single completion endpoint for all agent conversations. :::caution DEPRECATED -The previous endpoint `POST /api/v1/agents/{agent_id}/completions` is deprecated. Please use `POST /api/v1/agents/chat/completion` instead. +The API is deprecated. Please use `POST /api/v1/agents/chat/completions` instead. ::: #### Request - Method: POST -- URL: `/api/v1/agents/chat/completion` +- URL: `/api/v1/agents/chat/completions` - Headers: - `'content-Type: application/json'` - `'Authorization: Bearer '` @@ -4534,7 +4534,7 @@ If the **Begin** component does not take parameters: ```bash curl --request POST \ - --url http://{address}/api/v1/agents/chat/completion \ + --url http://{address}/api/v1/agents/chat/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data-binary ' @@ -4549,7 +4549,7 @@ curl --request POST \ ```bash curl --request POST \ - --url http://{address}/api/v1/agents/chat/completion \ + --url http://{address}/api/v1/agents/chat/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data-binary ' @@ -4586,7 +4586,7 @@ To continue an existing session: ```bash curl --request POST \ - --url http://{address}/api/v1/agents/chat/completion \ + --url http://{address}/api/v1/agents/chat/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data-binary ' @@ -4692,7 +4692,7 @@ Streaming request: ```bash curl --request POST \ - --url http://{address}/api/v1/agents/chat/completion \ + --url http://{address}/api/v1/agents/chat/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data-binary ' @@ -4713,7 +4713,7 @@ Non-stream request with existing session: ```bash curl --request POST \ - --url http://{address}/api/v1/agents/chat/completion \ + --url http://{address}/api/v1/agents/chat/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data-binary ' @@ -7806,14 +7806,14 @@ Failure: ### Search completion -**POST** `/api/v1/searches/{search_id}/completion` +**POST** `/api/v1/searches/{search_id}/completions` Generates an answer using the saved search app configuration and returns the result as a Server-Sent Events stream. #### Request - Method: POST -- URL: `/api/v1/searches/{search_id}/completion` +- URL: `/api/v1/searches/{search_id}/completions` - Headers: - `'Content-Type: application/json'` - `'Authorization: Bearer '` @@ -7825,7 +7825,7 @@ Generates an answer using the saved search app configuration and returns the res ```bash curl --request POST \ - --url http://{address}/api/v1/searches/{search_id}/completion \ + --url http://{address}/api/v1/searches/{search_id}/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ' \ --data '{ diff --git a/sdk/python/ragflow_sdk/modules/session.py b/sdk/python/ragflow_sdk/modules/session.py index 8f7e95dd7..f9c4799fd 100644 --- a/sdk/python/ragflow_sdk/modules/session.py +++ b/sdk/python/ragflow_sdk/modules/session.py @@ -116,7 +116,7 @@ class Session(Base): "openai-compatible": False, } json_data.update(kwargs) - res = self.post("/agents/chat/completion", json_data, stream=stream) + res = self.post("/agents/chat/completions", json_data, stream=stream) return res def update(self, update_message): diff --git a/test/testcases/test_http_api/common.py b/test/testcases/test_http_api/common.py index c79b8ebef..1e9041557 100644 --- a/test/testcases/test_http_api/common.py +++ b/test/testcases/test_http_api/common.py @@ -383,7 +383,7 @@ def delete_all_agent_sessions(auth, agent_id, *, page_size=1000): def agent_completions(auth, agent_id, payload=None): - url = f"{HOST_ADDRESS}{AGENT_API_URL}/chat/completion" + url = f"{HOST_ADDRESS}{AGENT_API_URL}/chat/completions" body = {"agent_id": agent_id} if payload: body.update(payload) diff --git a/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py b/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py index 7ab43ffd1..496958911 100644 --- a/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py +++ b/test/testcases/test_sdk_api/test_session_management/test_create_session_with_chat_assistant.py @@ -160,7 +160,7 @@ def test_session_module_streaming_and_helper_paths_unit(monkeypatch): assert calls[0][2]["session_id"] == "session-chat" assert calls[0][2]["temperature"] == 0.2 assert calls[0][3] is True - assert calls[1][1] == "/agents/chat/completion" + assert calls[1][1] == "/agents/chat/completions" assert calls[1][2]["agent_id"] == "agent-1" assert calls[1][2]["query"] == "hello agent" assert calls[1][2]["session_id"] == "session-agent" diff --git a/web/src/utils/api.ts b/web/src/utils/api.ts index 4bb5857d0..b1c2c3e6e 100644 --- a/web/src/utils/api.ts +++ b/web/src/utils/api.ts @@ -161,7 +161,7 @@ export default { completionUrl: `${restAPIv1}/chat/completions`, chatsTts: `${restAPIv1}/chat/audio/speech`, searchCompletion: (searchId: string) => - `${restAPIv1}/searches/${searchId}/completion`, + `${restAPIv1}/searches/${searchId}/completions`, chatsMindmap: `${restAPIv1}/chat/mindmap`, chatsRelatedQuestions: `${restAPIv1}/chat/recommendation`, @@ -192,7 +192,7 @@ export default { createAgent: `${restAPIv1}/agents`, updateAgent: (agentId: string) => `${restAPIv1}/agents/${agentId}`, deleteAgent: (agentId: string) => `${restAPIv1}/agents/${agentId}`, - agentChatCompletion: `${restAPIv1}/agents/chat/completion`, + agentChatCompletion: `${restAPIv1}/agents/chat/completions`, resetAgent: (agentId: string) => `${restAPIv1}/agents/${agentId}/reset`, testDbConnect: `${restAPIv1}/agents/test_db_connection`, getInputElements: `${webAPI}/canvas/input_elements`,