Skip to content

Commit

Permalink
test(unit): add schema description too long error test
Browse files Browse the repository at this point in the history
  • Loading branch information
Patai5 committed May 1, 2024
1 parent 9f5fa1c commit 1665f52
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions code/src/models/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,9 @@ export class OpenAIModelHandler extends GeneralModelHandler<OpenAIModelSettings>
return functionArguments || null;
};
}

/** Used for unit testing */
// eslint-disable-next-line no-underscore-dangle
export const _private = {
wrapInOpenaiError,
};
20 changes: 20 additions & 0 deletions code/test/unit/models/openai.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, test } from 'vitest';

import { DESCRIPTION_LENGTH_ERROR_LOG_MESSAGE, NonRetryableOpenaiAPIError } from '../../../src/errors';
import { _private } from '../../../src/models/openai';
import { LangchainError } from '../../../src/types/langchain-types';

const { wrapInOpenaiError } = _private;

describe('wrapInOpenaiError', () => {
test('should return help error message for "too long function description" error', () => {
const error = new Error() as LangchainError;
error.error = { message: "'blah blah too long blah' is too long - 'functions.0.description'" };
error.status = 400;

const wrappedError = wrapInOpenaiError(error as LangchainError);

expect(wrappedError).toBeInstanceOf(NonRetryableOpenaiAPIError);
expect(wrappedError.message).toBe(`OpenaiAPIError: ${DESCRIPTION_LENGTH_ERROR_LOG_MESSAGE}`);
});
});
3 changes: 0 additions & 3 deletions code/test/unit/todo.test.ts

This file was deleted.

0 comments on commit 1665f52

Please sign in to comment.