fix(formatMessages): Conform Name Property to OpenAI Expected Regex (#1076)

* fix(formatMessages): conform name property to OpenAI expected regex

* fix(ci): prior test was expecting non-sanitized name input
This commit is contained in:
Danny Avila 2023-10-19 10:02:20 -04:00 committed by GitHub
parent fd99bac121
commit abbc57a49a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View file

@ -18,6 +18,36 @@ describe('formatMessage', () => {
});
});
it('sanitizes the name by replacing invalid characters (per OpenAI)', () => {
const input = {
message: {
sender: 'user',
text: 'Hello',
},
userName: ' John$Doe@Example! ',
};
const result = formatMessage(input);
expect(result).toEqual({
role: 'user',
content: 'Hello',
name: '_John_Doe_Example__',
});
});
it('trims the name to a maximum length of 64 characters', () => {
const longName = 'a'.repeat(100);
const input = {
message: {
sender: 'user',
text: 'Hello',
},
userName: longName,
};
const result = formatMessage(input);
expect(result.name.length).toBe(64);
expect(result.name).toBe('a'.repeat(64));
});
it('formats a realistic user message', () => {
const input = {
message: {