Skip to content

Commit 1093bd0

Browse files
committed
throw when n>1
1 parent d1fb561 commit 1093bd0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/lib/beta/BetaToolRunner.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export class BetaToolRunner<Stream extends boolean> {
7272
params: BetaToolRunnerParams,
7373
options?: BetaToolRunnerRequestOptions,
7474
) {
75+
params.n ??= 1;
76+
if (params && params.n > 1) {
77+
throw new Error('BetaToolRunner does not support n > 1');
78+
}
79+
7580
this.#state = {
7681
params: {
7782
// You can't clone the entire params since there are functions as handlers.

tests/lib/tools/ToolRunner.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import OpenAI from 'openai';
2-
// import { BetaMessage, BetaContentBlock, BetaToolResultBlockParam } from 'openai/sdk/resources/beta';
3-
// import { BetaRunnableTool } from 'openai/sdk/lib/tools/BetaRunnableTool';
4-
// import { BetaRawMessageStreamEvent } from 'openai/sdk/resources/beta/messages';
5-
// import { Fetch } from 'openai/sdk/internal/builtin-types';
62
import { mockFetch } from '../../utils/mock-fetch';
73
import { BetaRunnableTool } from 'openai/lib/beta/BetaRunnableTool';
84
import {
@@ -432,6 +428,16 @@ describe('ToolRunner', () => {
432428
);
433429
});
434430

431+
it('throws when constructed with n>1', async () => {
432+
expect(() => {
433+
setupTest({ n: 999 });
434+
}).toThrow('BetaToolRunner does not support n > 1');
435+
436+
expect(() => {
437+
setupTest({ n: null });
438+
}).not.toThrow();
439+
});
440+
435441
describe('iterator.next()', () => {
436442
it('yields CompletionMessage', async () => {
437443
const { runner, handleAssistantMessage } = setupTest();

0 commit comments

Comments
 (0)