Skip to content

Commit bca33ff

Browse files
committed
fix tool message not added bug
1 parent ec35753 commit bca33ff

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

gui/src/pages/gui/ToolCallDiv/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function getStatusIcon(state: ToolStatus) {
6969
export function ToolCallDiv(props: ToolCallDivProps) {
7070
const availableTools = useAppSelector((state) => state.config.config.tools);
7171
const tool = useMemo(() => {
72+
console.log(availableTools, props.toolCall);
7273
return availableTools.find(
7374
(tool) => props.toolCall.function?.name === tool.function.name,
7475
);

gui/src/redux/slices/sessionSlice.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ export const sessionSlice = createSlice({
295295
const newHistoryItem =
296296
createThinkingChatHistoryItem(incomingMessage);
297297
state.history.push(newHistoryItem);
298+
} else if (incomingMessage.role === "tool") {
299+
state.history.push({
300+
message: {
301+
...incomingMessage,
302+
id: uuidv4(),
303+
},
304+
contextItems: [],
305+
});
298306
} else {
299307
continue;
300308
}

gui/src/util/toolCallState.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ export function addToolCallDeltaToState(
3030
const nameDelta = toolCallDelta.function?.name ?? "";
3131
const argsDelta = toolCallDelta.function?.arguments ?? "";
3232

33-
const mergedName =
34-
currentName === nameDelta ? currentName : currentName + nameDelta; // Some models may include the name repeatedly. This doesn't account for an edge case where the name is like "dothisdothis" and it happens to stream name in chunks "dothis" and "dothis" but that's a super edge case
33+
let mergedName = currentName;
34+
if (nameDelta.startsWith(currentName)) {
35+
// Case where model progresssively streams name but full name each time e.g. "readFi" -> "readFil" -> "readFile"
36+
mergedName = nameDelta;
37+
} else if (currentName.startsWith(nameDelta)) {
38+
// Case where model streams in full name each time e.g. readFile -> readFile -> readFile
39+
// do nothing
40+
} else {
41+
// Case where model streams in name in parts e.g. "read" -> "File"
42+
mergedName = currentName + nameDelta;
43+
}
3544
const mergedArgs = currentArgs + argsDelta;
3645

3746
const [_, parsedArgs] = incrementalParseJson(mergedArgs || "{}");

0 commit comments

Comments
 (0)