From 8525f55ad0e993116ac4241a545706b811a4dc32 Mon Sep 17 00:00:00 2001 From: petertc Date: Wed, 19 Feb 2025 13:18:51 +0800 Subject: [PATCH] Fix: Option ineffective in Chat API (#5118) ### What problem does this PR solve? API options like `stream` was ignored when no session_id was provided. This PR fixes the issue. Test command and expected result: ``` curl --request POST \ --url http://:9222/api/v1/chats/2f2e1d30ee6111efafe211749b004925/completions \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ragflow-xxx' \ --data '{ "question":"Who are you", "stream":false }' {"code":0,"data":"data:{\"code\": 0, \"message\": \"\", \"data\": {\"answer\": \"Hi! I'm your assistant, what can I do for you?\", \"reference\": {}, \"audio_binary\": null, \"id\": null, \"session_id\": \"82ceb0fcee7111efafe211749b004925\"}}\n\n"} ``` ### Type of change - [*] Bug Fix (non-breaking change which fixes an issue) --- api/apps/sdk/session.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index 2e78d4e3a..f2fd6ab66 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -159,8 +159,10 @@ def update(tenant_id, chat_id, session_id): @token_required def chat_completion(tenant_id, chat_id): req = request.json - if not req or not req.get("session_id"): + if not req: req = {"question": ""} + if not req.get("session_id"): + req["question"]="" if not DialogService.query(tenant_id=tenant_id, id=chat_id, status=StatusEnum.VALID.value): return get_error_data_result(f"You don't own the chat {chat_id}") if req.get("session_id"):