Skip to content

Commit

Permalink
fix for stop sequence array
Browse files Browse the repository at this point in the history
  • Loading branch information
ZbynekPelunek committed Jan 14, 2025
1 parent fa4bb43 commit b18335a
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ module.exports = {
role: content.model.includes('o1') && message.role === 'system' ? 'developer' : message.role,
content: message.content
}));
context.log({ step: 'transformedMessages', transformedMessages });
const transformedStopSequence = content.stop.ADD.map(sequence => {
if (Object.keys(sequence).length > 0 && sequence.sequence !== '') {
const transformedStopSequence = content.stop.ADD.reduce((acc, sequence) => {
if (sequence.sequence) {
context.log({ step: 'sequence check', check: `sequence is not null or empty string: ${sequence.sequence}` });
return sequence.sequence;
acc.push(sequence.sequence);
}
});
const filteredStopSequence = transformedStopSequence.filter(s => s !== '');
context.log({ step: 'transformedStopSequence', transformedStopSequence });
context.log({ step: 'filteredStopSequence', filteredStopSequence });
return acc;
}, []);

if (transformedStopSequence.length > 4) {
throw new context.CancelError('Request can have a maximum of 4 stop sequences.');
Expand All @@ -27,11 +24,9 @@ module.exports = {
const requestBody = {
...content,
messages: transformedMessages,
stop: filteredStopSequence.length > 0 ? filteredStopSequence : undefined
stop: transformedStopSequence.length > 0 ? transformedStopSequence : undefined
};

context.log({ step: 'requestBody', requestBody });

const req = {
url: 'https://api.openai.com/v1/chat/completions',
method: 'POST',
Expand Down

0 comments on commit b18335a

Please sign in to comment.