Skip to content

Commit d66e38c

Browse files
committed
fix: message coercion for tool call message
Some services can't tolerate a message with tool calls and an empty array set on the content property, despite the fact that OpenAI does seem to support this.
1 parent 9d18174 commit d66e38c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/src/modules/puterai/lib/OpenAIUtil.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ module.exports = class OpenAIUtil {
2424
}
2525

2626
// coerce tool calls
27+
let is_tool_call = false;
2728
for ( let i = content.length - 1 ; i >= 0 ; i-- ) {
2829
const content_block = content[i];
2930

3031
if ( content_block.type === 'tool_use' ) {
3132
if ( ! msg.hasOwnProperty('tool_calls') ) {
3233
msg.tool_calls = [];
34+
is_tool_call = true;
3335
}
3436
msg.tool_calls.push({
3537
id: content_block.id,
@@ -43,6 +45,8 @@ module.exports = class OpenAIUtil {
4345
}
4446
}
4547

48+
if ( is_tool_call ) msg.content = null;
49+
4650
// coerce tool results
4751
// (we assume multiple tool results were already split into separate messages)
4852
for ( let i = content.length - 1 ; i >= 0 ; i-- ) {

0 commit comments

Comments
 (0)