mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-05-30 04:27:30 +08:00
Refactor: completion -> completions (#14584)
### What problem does this PR solve? Keep only /completions, deprecated /completion ### Type of change - [x] Refactoring
This commit is contained in:
@ -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}")
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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
|
||||
@login_required
|
||||
@validate_request("question")
|
||||
async def completion(search_id):
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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>'`
|
||||
@ -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 '
|
||||
@ -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 '
|
||||
@ -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 '
|
||||
@ -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 '
|
||||
@ -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 '
|
||||
@ -7806,14 +7806,14 @@ Failure:
|
||||
```bash
|
||||
curl --request POST \
|
||||
--url http://{address}/api/v1/searches/{search_id}/completions \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'Authorization: Bearer <YOUR_LOGIN_TOKEN>' \
|
||||
--data '{
|
||||
"question": "What is retrieval-augmented generation?"
|
||||
}'
|
||||
```
|
||||
|
||||
##### Request parameters
|
||||
##### Request parameters
|
||||
|
||||
- `search_id`: (*Path parameter*), `string`, *Required*
|
||||
The ID of the search app.
|
||||
@ -7825,7 +7825,7 @@ Generates an answer using the saved search app configuration and returns the res
|
||||
#### Response
|
||||
|
||||
Success (streaming):
|
||||
|
||||
|
||||
```text
|
||||
data: {"code": 0, "message": "", "data": {"answer": "...", "reference": {...}}}
|
||||
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user