Skip to content

Commit 141f0ce

Browse files
authoredFeb 20, 2024
Add test and changeset for onFinal callback fix (#985)
1 parent 4afa012 commit 141f0ce

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
 

‎.changeset/ten-sloths-perform.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
Fix: onFinal callback is invoked with text from onToolCall when onToolCall returns string

‎packages/core/streams/openai-stream.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,25 @@ describe('OpenAIStream', () => {
353353
],
354354
});
355355
});
356+
357+
it('should call onFinal with tool response when onToolCall returns string', async () => {
358+
let finalResponse: any = undefined;
359+
360+
const stream = OpenAIStream(await fetch(TOOL_CALL_TEST_URL), {
361+
async experimental_onToolCall(payload, appendToolCallMessage) {
362+
return 'tool-response';
363+
},
364+
365+
onFinal(response) {
366+
finalResponse = response;
367+
},
368+
});
369+
370+
const response = new StreamingTextResponse(stream);
371+
await createClient(response).readAll(); // consume stream
372+
373+
expect(finalResponse).toEqual('tool-response');
374+
});
356375
});
357376

358377
describe('Azure SDK', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.