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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions admin/client/ragflow_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,12 +1215,12 @@ def chat_on_session(self, command):
# 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}")
Expand Down
6 changes: 3 additions & 3 deletions api/apps/backward_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions api/apps/restful_apis/agent_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines 848 to +849
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Deprecated singular agent route is still first-class in the main API.
Line 848 keeps /agents/chat/completion active without deprecation handling. That conflicts with the objective to keep only /completions. Recommend removing the singular decorator from this handler and serving old-path compatibility only via backward-compat routes with warnings.

Suggested diff
-@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):
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apps/restful_apis/agent_api.py` around lines 848 - 849, Remove the
deprecated singular route decorator "@manager.route(\"/agents/chat/completion\",
methods=[\"POST\"])" from the handler so only "/agents/chat/completions" is
registered as the primary endpoint; ensure the handler (the function decorated
with manager.route for completions) remains unchanged. Add a separate
backward-compatibility wrapper route elsewhere that registers
"/agents/chat/completion" and calls the same handler but logs/emits a
deprecation warning (use the existing logging facility) before forwarding the
request. Make sure to reference the same handler function when forwarding to
avoid duplicating logic and keep only the plural route as first-class.

@login_required
@add_tenant_id_to_kwargs
async def agent_chat_completion(tenant_id, agent_id=None):
Expand Down
1 change: 1 addition & 0 deletions api/apps/restful_apis/search_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def delete_search(search_id):


@manager.route("/searches/<search_id>/completion", methods=["POST"]) # noqa: F821
@manager.route("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
Comment on lines 176 to +177
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Primary API still exposes deprecated singular /completion path.
Line 176 keeps the old route active in the main API module, which contradicts the stated migration goal (“keep only /completions and deprecate /completion”). Please remove the singular route here and keep any compatibility shim only in api/apps/backward_compat.py with explicit warning logs.

Suggested diff
-@manager.route("/searches/<search_id>/completion", methods=["POST"])  # noqa: F821
 `@manager.route`("/searches/<search_id>/completions", methods=["POST"])  # noqa: F821
 `@login_required`
 `@validate_request`("question")
 async def completion(search_id):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@manager.route("/searches/<search_id>/completion", methods=["POST"]) # noqa: F821
@manager.route("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
`@manager.route`("/searches/<search_id>/completions", methods=["POST"]) # noqa: F821
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/apps/restful_apis/search_api.py` around lines 176 - 177, Remove the
deprecated singular route by deleting the
`@manager.route`("/searches/<search_id>/completion", methods=["POST"]) decorator
in search_api.py so only the plural
`@manager.route`("/searches/<search_id>/completions", methods=["POST"]) remains;
if a compatibility shim is required, implement it only inside
api/apps/backward_compat.py (not in this module) and ensure that shim logs an
explicit deprecation warning when invoked.

@login_required
@validate_request("question")
async def completion(search_id):
Expand Down
2 changes: 1 addition & 1 deletion api/apps/services/canvas_replica_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def bootstrap(

@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)

Expand Down
20 changes: 10 additions & 10 deletions docs/references/http_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <YOUR_API_KEY>'`
Expand Down Expand Up @@ -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 <YOUR_API_KEY>' \
--data-binary '
Expand All @@ -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 <YOUR_API_KEY>' \
--data-binary '
Expand Down Expand Up @@ -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 <YOUR_API_KEY>' \
--data-binary '
Expand Down Expand Up @@ -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 <YOUR_API_KEY>' \
--data-binary '
Expand All @@ -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 <YOUR_API_KEY>' \
--data-binary '
Expand Down Expand Up @@ -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 <YOUR_LOGIN_TOKEN>'`
Expand All @@ -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 <YOUR_LOGIN_TOKEN>' \
--data '{
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/ragflow_sdk/modules/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _ask_agent(self, question: str, stream: bool, **kwargs):
"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):
Expand Down
2 changes: 1 addition & 1 deletion test/testcases/test_http_api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _agent_post(path, json=None, stream=False, files=None):
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"
Expand Down
4 changes: 2 additions & 2 deletions web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,

Expand Down Expand Up @@ -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`,
Expand Down
Loading