Skip to content

Commit

Permalink
Add test and changeset for onFinal callback fix (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Feb 20, 2024
1 parent 4afa012 commit 141f0ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-sloths-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ai': patch
---

Fix: onFinal callback is invoked with text from onToolCall when onToolCall returns string
19 changes: 19 additions & 0 deletions packages/core/streams/openai-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ describe('OpenAIStream', () => {
],
});
});

it('should call onFinal with tool response when onToolCall returns string', async () => {
let finalResponse: any = undefined;

const stream = OpenAIStream(await fetch(TOOL_CALL_TEST_URL), {
async experimental_onToolCall(payload, appendToolCallMessage) {
return 'tool-response';
},

onFinal(response) {
finalResponse = response;
},
});

const response = new StreamingTextResponse(stream);
await createClient(response).readAll(); // consume stream

expect(finalResponse).toEqual('tool-response');
});
});

describe('Azure SDK', () => {
Expand Down

0 comments on commit 141f0ce

Please sign in to comment.