mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 17:00:15 +01:00
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:
parent
fd99bac121
commit
abbc57a49a
3 changed files with 41 additions and 1 deletions
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue