Skip to content

Commit 8e1c4c9

Browse files
authored
fix(ollama): fix duplicate tool response (#3707)
1 parent 2d9a00c commit 8e1c4c9

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

js/plugins/ollama/src/index.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -430,21 +430,28 @@ function toOllamaRequest(
430430
toolResponses.push(c.toolResponse);
431431
}
432432
});
433-
// Add tool responses, if any.
434-
toolResponses.forEach((t) => {
433+
if (toolResponses.length > 0) {
434+
toolResponses.forEach((t) => {
435+
messages.push({
436+
role,
437+
content:
438+
typeof t.output === 'string'
439+
? t.output
440+
: JSON.stringify(t.output),
441+
tool_name: t.name,
442+
});
443+
});
444+
} else {
435445
messages.push({
436-
role,
437-
content:
438-
typeof t.output === 'string' ? t.output : JSON.stringify(t.output),
446+
role: role,
447+
content: toolRequests.length > 0 ? '' : messageText,
448+
images: images.length > 0 ? images : undefined,
449+
tool_calls:
450+
toolRequests.length > 0
451+
? toOllamaToolCall(toolRequests)
452+
: undefined,
439453
});
440-
});
441-
messages.push({
442-
role: role,
443-
content: toolRequests.length > 0 ? '' : messageText,
444-
images: images.length > 0 ? images : undefined,
445-
tool_calls:
446-
toolRequests.length > 0 ? toOllamaToolCall(toolRequests) : undefined,
447-
});
454+
}
448455
});
449456
request.messages = messages;
450457
} else {

js/plugins/ollama/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ export interface OllamaToolCall {
152152
export interface Message {
153153
role: string;
154154
content: string;
155+
thinking?: string;
155156
images?: string[];
156157
tool_calls?: any[];
158+
tool_name?: string;
157159
}
158160

159161
// Ollama local model definition

0 commit comments

Comments
 (0)