fix: new edge cases with function calls / tools
Docker Image CI / build-and-push-image (push) Waiting to run
Maintain Release Merge PR / update-release-pr (push) Waiting to run
release-please / release-please (push) Waiting to run
test / test (18.x) (push) Waiting to run
test / test (20.x) (push) Waiting to run
test / test (22.x) (push) Waiting to run

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
@@ -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) ) {
@@ -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');
}