fix: new edge cases with function calls / tools

This commit is contained in:
KernelDeimos 2025-01-22 19:55:33 -05:00
parent 1256614ec2
commit 9cbb741a8a
2 changed files with 7 additions and 0 deletions

View File

@ -551,6 +551,10 @@ class AIChatService extends BaseService {
async moderate ({ messages }) {
for ( const msg of messages ) {
const texts = [];
// Function calls have no content
if ( msg.content === null ) continue;
if ( typeof msg.content === 'string' ) texts.push(msg.content);
else if ( typeof msg.content === 'object' ) {
if ( Array.isArray(msg.content) ) {

View File

@ -258,6 +258,9 @@ class OpenAICompletionService extends BaseService {
throw new Error('each message must be a string or an object');
}
if ( ! msg.role ) msg.role = 'user';
if ( msg.role === 'assistant' && ! msg.content ) {
continue;
}
if ( ! msg.content ) {
throw new Error('each message must have a `content` property');
}