mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-25 09:32:38 +08:00
Refa: align chat and search restful APIs (#14229)
### What problem does this PR solve? Refactor /api/v1/chats to be more RESTful. ### Type of change - [x] Refactoring --------- Co-authored-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -267,7 +267,7 @@ def list_session_with_chat_assistants(auth, chat_assistant_id, params=None):
|
||||
|
||||
def update_session_with_chat_assistant(auth, chat_assistant_id, session_id, payload=None):
|
||||
url = f"{HOST_ADDRESS}{SESSION_WITH_CHAT_ASSISTANT_API_URL}/{session_id}".format(chat_id=chat_assistant_id)
|
||||
res = requests.put(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
res = requests.patch(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ def agent_completions(auth, agent_id, payload=None):
|
||||
return res.json()
|
||||
|
||||
|
||||
def chat_completions(auth, chat_id, payload=None):
|
||||
def chat_completions(auth, chat_id=None, payload=None):
|
||||
"""
|
||||
Send a question/message to a chat assistant and get completion.
|
||||
|
||||
@@ -403,14 +403,19 @@ def chat_completions(auth, chat_id, payload=None):
|
||||
auth: Authentication object
|
||||
chat_id: Chat assistant ID
|
||||
payload: Dictionary containing:
|
||||
- question: str (required) - The question to ask
|
||||
- messages: list (required) - Conversation messages
|
||||
- stream: bool (optional) - Whether to stream responses, default False
|
||||
- session_id: str (optional) - Session ID for conversation context
|
||||
|
||||
Returns:
|
||||
Response JSON with answer data
|
||||
"""
|
||||
url = f"{HOST_ADDRESS}/api/{VERSION}/chats/{chat_id}/completions"
|
||||
url = f"{HOST_ADDRESS}/api/{VERSION}/chat/completions"
|
||||
payload = dict(payload or {})
|
||||
if chat_id:
|
||||
payload.setdefault("chat_id", chat_id)
|
||||
if "question" in payload and "messages" not in payload:
|
||||
payload["messages"] = [{"role": "user", "content": payload.pop("question")}]
|
||||
res = requests.post(url=url, headers=HEADERS, auth=auth, json=payload)
|
||||
return res.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user