From a1dc2da7b4ae4f8914a5acc312c058c4fd074da8 Mon Sep 17 00:00:00 2001 From: zaviermeekz-cpu Date: Thu, 11 Jun 2026 02:38:37 -0400 Subject: [PATCH] fix: add model_name to embed completion request (#15883) (#15888) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? When embedding a chatbot, the API returned `"Model Name is required"`. The embed widget now includes the assistant's `llm_id` as `model_name` in the completion request. ### Type of change - [x] Bug Fix ### How has this been tested? - Created a chatbot with a default model. - Embedded it and sent a message – the error is gone and the assistant replies correctly. ### Related Issue Closes #15883 Co-authored-by: RAGFlow Dev Co-authored-by: Wang Qi --- api/apps/restful_apis/bot_api.py | 1 + web/src/interfaces/database/chat.ts | 1 + web/src/pages/next-chats/hooks/use-send-shared-message.ts | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/api/apps/restful_apis/bot_api.py b/api/apps/restful_apis/bot_api.py index 19e894ddb8..0081157be8 100644 --- a/api/apps/restful_apis/bot_api.py +++ b/api/apps/restful_apis/bot_api.py @@ -149,6 +149,7 @@ async def chatbots_inputs(dialog_id, tenant_id=None): "avatar": dialog.icon, "prologue": dialog.prompt_config.get("prologue", ""), "has_tavily_key": bool(dialog.prompt_config.get("tavily_api_key", "").strip()), + "llm_id": dialog.llm_id or "", } ) diff --git a/web/src/interfaces/database/chat.ts b/web/src/interfaces/database/chat.ts index 447409bcf8..2bd8d4c3a0 100644 --- a/web/src/interfaces/database/chat.ts +++ b/web/src/interfaces/database/chat.ts @@ -202,6 +202,7 @@ export interface IExternalChatInfo { title: string; prologue?: string; has_tavily_key?: boolean; + llm_id?: string; } export interface IMessage extends Message { diff --git a/web/src/pages/next-chats/hooks/use-send-shared-message.ts b/web/src/pages/next-chats/hooks/use-send-shared-message.ts index de99d344e3..3d66ea0290 100644 --- a/web/src/pages/next-chats/hooks/use-send-shared-message.ts +++ b/web/src/pages/next-chats/hooks/use-send-shared-message.ts @@ -6,6 +6,7 @@ import { useSelectDerivedMessages, useSendMessageWithSse, } from '@/hooks/logic-hooks'; +import { useFetchExternalChatInfo } from '@/hooks/use-chat-request'; import { Message } from '@/interfaces/database/chat'; import { get } from 'lodash'; import trim from 'lodash/trim'; @@ -48,6 +49,7 @@ export const useSendSharedMessage = () => { } = useGetSharedChatSearchParams(); const { handleInputChange, value, setValue } = useHandleMessageInputChange(); const completionUrl = `/api/v1/${from === SharedFrom.Agent ? 'agentbots' : 'chatbots'}/${conversationId}/completions`; + const { data: chatInfo } = useFetchExternalChatInfo(); const { send, answer, done, stopOutputMessage } = useSendMessageWithSse(); const { derivedMessages, @@ -75,6 +77,7 @@ export const useSendSharedMessage = () => { session_id: get(derivedMessages, '0.session_id'), reasoning: enableThinking, internet: enableInternet, + ...(chatInfo?.llm_id ? { model_name: chatInfo.llm_id } : {}), }); if (isCompletionError(res)) { @@ -90,6 +93,7 @@ export const useSendSharedMessage = () => { derivedMessages, setValue, removeLatestMessage, + chatInfo, ], ); @@ -108,7 +112,7 @@ export const useSendSharedMessage = () => { const payload = { question: '' }; const ret = await send(completionUrl, { ...payload, ...data }); if (isCompletionError(ret)) { - message.error(ret?.data.message); + message.error(ret?.data.message ?? 'Unknown error'); setHasError(true); } }, [send, completionUrl]);