Skip to content

Commit

Permalink
fix(weave): Prevent sending null message in playground (#3278)
Browse files Browse the repository at this point in the history
* Filter null messages, prevent sending null message

* clean
  • Loading branch information
jwlee64 authored Dec 18, 2024
1 parent 5fc28f2 commit 6a093a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const PlaygroundChat = ({
const {handleRetry, handleSend} = useChatCompletionFunctions(
setPlaygroundStates,
setIsLoading,
chatText,
playgroundStates,
entity,
project,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -43,7 +43,7 @@ export const PlaygroundChatInput: React.FC<PlaygroundChatInputProps> = ({
};

const handleSend = (role: PlaygroundMessageRole) => {
onSend(role);
onSend(role, chatText);
handleReset();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6a093a4

Please sign in to comment.