|
1 | 1 | import OpenAI from 'openai'; |
2 | 2 | import { mockFetch } from '../../utils/mock-fetch'; |
3 | | -import { BetaRunnableTool } from 'openai/lib/beta/BetaRunnableTool'; |
4 | | -import { |
| 3 | +import type { BetaRunnableTool } from 'openai/lib/beta/BetaRunnableTool'; |
| 4 | +import type { |
5 | 5 | ChatCompletion, |
6 | 6 | ChatCompletionChunk, |
7 | 7 | ChatCompletionMessage, |
8 | 8 | ChatCompletionMessageFunctionToolCall, |
9 | 9 | ChatCompletionMessageToolCall, |
10 | 10 | ChatCompletionToolMessageParam, |
11 | 11 | } from 'openai/resources'; |
12 | | -import { Fetch } from 'openai/internal/builtin-types'; |
| 12 | +import type { Fetch } from 'openai/internal/builtin-types'; |
| 13 | +import type { BetaToolRunnerParams } from 'openai/lib/beta/BetaToolRunner'; |
13 | 14 |
|
14 | 15 | const weatherTool: BetaRunnableTool<{ location: string }> = { |
15 | 16 | type: 'function', |
@@ -286,13 +287,11 @@ interface SetupTestResult<Stream extends boolean> { |
286 | 287 | handleAssistantMessageStream: (messageContentOrToolCalls?: ToolCallsOrMessage) => ChatCompletion; |
287 | 288 | } |
288 | 289 |
|
289 | | -type ToolRunnerParams = Parameters<typeof OpenAI.Beta.Chat.Completions.prototype.toolRunner>[0]; |
290 | | - |
291 | 290 | type ToolCallsOrMessage = ChatCompletionMessageToolCall[] | ChatCompletionMessage; |
292 | 291 |
|
293 | | -function setupTest(params?: Partial<ToolRunnerParams> & { stream?: false }): SetupTestResult<false>; |
294 | | -function setupTest(params: Partial<ToolRunnerParams> & { stream: true }): SetupTestResult<true>; |
295 | | -function setupTest(params: Partial<ToolRunnerParams> = {}): SetupTestResult<boolean> { |
| 292 | +function setupTest(params?: Partial<BetaToolRunnerParams> & { stream?: false }): SetupTestResult<false>; |
| 293 | +function setupTest(params: Partial<BetaToolRunnerParams> & { stream: true }): SetupTestResult<true>; |
| 294 | +function setupTest(params: Partial<BetaToolRunnerParams> = {}): SetupTestResult<boolean> { |
296 | 295 | const { handleRequest, handleStreamEvents, fetch } = mockFetch(); |
297 | 296 | let messageIdCounter = 0; |
298 | 297 | const handleAssistantMessage: SetupTestResult<false>['handleAssistantMessage'] = ( |
@@ -380,7 +379,7 @@ function setupTest(params: Partial<ToolRunnerParams> = {}): SetupTestResult<bool |
380 | 379 |
|
381 | 380 | const client = new OpenAI({ apiKey: 'test-key', fetch: fetch, maxRetries: 0 }); |
382 | 381 |
|
383 | | - const runnerParams: ToolRunnerParams = { |
| 382 | + const runnerParams: BetaToolRunnerParams = { |
384 | 383 | messages: params.messages || [{ role: 'user', content: 'What is the weather?' }], |
385 | 384 | model: params.model || 'gpt-4o', |
386 | 385 | max_tokens: params.max_tokens || 1000, |
|
0 commit comments