From 6a093a4f2d8088e0d5e02c6ca2a5688cc017ac0d Mon Sep 17 00:00:00 2001 From: Josiah Lee Date: Tue, 17 Dec 2024 18:01:08 -0800 Subject: [PATCH] fix(weave): Prevent sending null message in playground (#3278) * Filter null messages, prevent sending null message * clean --- .../PlaygroundPage/PlaygroundChat/PlaygroundChat.tsx | 9 +++++++-- .../PlaygroundChat/PlaygroundChatInput.tsx | 6 +++--- .../PlaygroundChat/useChatCompletionFunctions.tsx | 8 +++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChat.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChat.tsx index b6b6e7c420d3..8fc02fea9b10 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChat.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChat.tsx @@ -41,7 +41,6 @@ export const PlaygroundChat = ({ const {handleRetry, handleSend} = useChatCompletionFunctions( setPlaygroundStates, setIsLoading, - chatText, playgroundStates, entity, project, @@ -168,7 +167,13 @@ export const PlaygroundChat = ({ content: string, toolCallId?: string ) => { - handleSend(role, idx, content, toolCallId); + handleSend( + role, + chatText, + idx, + content, + toolCallId + ); }, setSelectedChoiceIndex: (choiceIndex: number) => setPlaygroundStateField( diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChatInput.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChatInput.tsx index cac631a8fcf8..d1a627fc4833 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChatInput.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/PlaygroundChatInput.tsx @@ -10,8 +10,8 @@ type PlaygroundChatInputProps = { chatText: string; setChatText: (text: string) => void; isLoading: boolean; - onSend: (role: PlaygroundMessageRole) => void; - onAdd: (role: PlaygroundMessageRole, text: string) => void; + onSend: (role: PlaygroundMessageRole, chatText: string) => void; + onAdd: (role: PlaygroundMessageRole, chatText: string) => void; settingsTab: number | null; }; @@ -43,7 +43,7 @@ export const PlaygroundChatInput: React.FC = ({ }; const handleSend = (role: PlaygroundMessageRole) => { - onSend(role); + onSend(role, chatText); handleReset(); }; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/useChatCompletionFunctions.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/useChatCompletionFunctions.tsx index c73e5d429190..80e4a32d0add 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/useChatCompletionFunctions.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/useChatCompletionFunctions.tsx @@ -13,7 +13,6 @@ import {clearTraceCall} from './useChatFunctions'; export const useChatCompletionFunctions = ( setPlaygroundStates: (states: PlaygroundState[]) => void, setIsLoading: (isLoading: boolean) => void, - chatText: string, playgroundStates: PlaygroundState[], entity: string, project: string, @@ -59,19 +58,22 @@ export const useChatCompletionFunctions = ( const handleSend = async ( role: PlaygroundMessageRole, + chatText: string, callIndex?: number, content?: string, toolCallId?: string ) => { try { setIsLoading(true); - const newMessage = createMessage(role, content || chatText, toolCallId); + const newMessageContent = content || chatText; + const newMessage = createMessage(role, newMessageContent, toolCallId); const updatedStates = playgroundStates.map((state, index) => { if (callIndex !== undefined && callIndex !== index) { return state; } const updatedState = appendChoiceToMessages(state); - if (updatedState.traceCall?.inputs?.messages) { + // If the new message is not empty, add it to the messages + if (newMessageContent && updatedState.traceCall?.inputs?.messages) { updatedState.traceCall.inputs.messages.push(newMessage); } return updatedState;