Capture the request body sent to OpenAI by mocking the client.
( provider: KimiChatProvider, systemPrompt: string, tools: Tool[], history: Message[], )
| 47 | |
| 48 | /** Capture the request body sent to OpenAI by mocking the client. */ |
| 49 | async function captureRequestBody( |
| 50 | provider: KimiChatProvider, |
| 51 | systemPrompt: string, |
| 52 | tools: Tool[], |
| 53 | history: Message[], |
| 54 | ): Promise<Record<string, unknown>> { |
| 55 | let capturedBody: Record<string, unknown> | undefined; |
| 56 | |
| 57 | (provider as any)._client.chat.completions.create = vi |
| 58 | .fn() |
| 59 | .mockImplementation((params: unknown) => { |
| 60 | capturedBody = params as Record<string, unknown>; |
| 61 | return Promise.resolve(makeChatCompletionResponse('kimi-k2')); |
| 62 | }); |
| 63 | |
| 64 | const stream = await provider.generate(systemPrompt, tools, history); |
| 65 | for await (const part of stream) { |
| 66 | void part; |
| 67 | } |
| 68 | |
| 69 | if (capturedBody === undefined) { |
| 70 | throw new Error('Expected provider.generate() to call chat.completions.create'); |
| 71 | } |
| 72 | return capturedBody; |
| 73 | } |
| 74 | |
| 75 | const ADD_TOOL: Tool = { |
| 76 | name: 'add', |
no test coverage detected