Skip to content

Commit 9cbb741

Browse files
committed
fix: new edge cases with function calls / tools
1 parent 1256614 commit 9cbb741

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/backend/src/modules/puterai/AIChatService.js

+4
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,10 @@ class AIChatService extends BaseService {
551551
async moderate ({ messages }) {
552552
for ( const msg of messages ) {
553553
const texts = [];
554+
555+
// Function calls have no content
556+
if ( msg.content === null ) continue;
557+
554558
if ( typeof msg.content === 'string' ) texts.push(msg.content);
555559
else if ( typeof msg.content === 'object' ) {
556560
if ( Array.isArray(msg.content) ) {

src/backend/src/modules/puterai/OpenAICompletionService.js

+3
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ class OpenAICompletionService extends BaseService {
258258
throw new Error('each message must be a string or an object');
259259
}
260260
if ( ! msg.role ) msg.role = 'user';
261+
if ( msg.role === 'assistant' && ! msg.content ) {
262+
continue;
263+
}
261264
if ( ! msg.content ) {
262265
throw new Error('each message must have a `content` property');
263266
}

0 commit comments

Comments
 (0)