Skip to content

Commit 1665f52

Browse files
committed
test(unit): add schema description too long error test
1 parent 9f5fa1c commit 1665f52

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

code/src/models/openai.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,9 @@ export class OpenAIModelHandler extends GeneralModelHandler<OpenAIModelSettings>
142142
return functionArguments || null;
143143
};
144144
}
145+
146+
/** Used for unit testing */
147+
// eslint-disable-next-line no-underscore-dangle
148+
export const _private = {
149+
wrapInOpenaiError,
150+
};

code/test/unit/models/openai.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, test } from 'vitest';
2+
3+
import { DESCRIPTION_LENGTH_ERROR_LOG_MESSAGE, NonRetryableOpenaiAPIError } from '../../../src/errors';
4+
import { _private } from '../../../src/models/openai';
5+
import { LangchainError } from '../../../src/types/langchain-types';
6+
7+
const { wrapInOpenaiError } = _private;
8+
9+
describe('wrapInOpenaiError', () => {
10+
test('should return help error message for "too long function description" error', () => {
11+
const error = new Error() as LangchainError;
12+
error.error = { message: "'blah blah too long blah' is too long - 'functions.0.description'" };
13+
error.status = 400;
14+
15+
const wrappedError = wrapInOpenaiError(error as LangchainError);
16+
17+
expect(wrappedError).toBeInstanceOf(NonRetryableOpenaiAPIError);
18+
expect(wrappedError.message).toBe(`OpenaiAPIError: ${DESCRIPTION_LENGTH_ERROR_LOG_MESSAGE}`);
19+
});
20+
});

code/test/unit/todo.test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)