Skip to content

Commit c1a045b

Browse files
committed
clean up
1 parent 46d0b30 commit c1a045b

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

weave-js/src/components/PagePanelComponents/Home/Browse3/pages/PlaygroundPage/PlaygroundChat/useChatCompletionFunctions.tsx

+21-20
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,27 @@ export const useChatCompletionFunctions = (
123123
choiceIndex?: number
124124
) => {
125125
try {
126-
// Update the chat state to prepare for retry
127-
const updatedStates = [...playgroundStates];
128-
let updatedState;
129-
130-
if (choiceIndex !== undefined) {
131-
updatedState = appendChoiceToMessages(
132-
playgroundStates[callIndex],
133-
choiceIndex
134-
);
135-
} else {
136-
updatedState = JSON.parse(JSON.stringify(playgroundStates[callIndex]));
137-
if (updatedState.traceCall?.inputs?.messages) {
138-
updatedState.traceCall.inputs.messages =
139-
updatedState.traceCall.inputs.messages.slice(0, messageIndex + 1);
140-
}
141-
}
142-
updatedState.loading = true;
143-
144-
updatedStates[callIndex] = filterNullMessages(updatedState);
145-
setPlaygroundStates(updatedStates);
126+
setPlaygroundStateField(callIndex, 'loading', true);
127+
128+
const updatedStates = filterNullMessagesFromStates(
129+
playgroundStates.map((state, index) => {
130+
if (index === callIndex) {
131+
if (choiceIndex !== undefined) {
132+
return appendChoiceToMessages(state, choiceIndex);
133+
}
134+
const updatedState = JSON.parse(JSON.stringify(state));
135+
if (updatedState.traceCall?.inputs?.messages) {
136+
updatedState.traceCall.inputs.messages =
137+
updatedState.traceCall.inputs.messages.slice(
138+
0,
139+
messageIndex + 1
140+
);
141+
}
142+
return updatedState;
143+
}
144+
return state;
145+
})
146+
);
146147

147148
const response = await makeCompletionRequest(callIndex, updatedStates);
148149

0 commit comments

Comments
 (0)