Skip to content

Commit

Permalink
Parse tool call arguments for onToolCall callback. (#1113)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel authored Mar 6, 2024
1 parent bb94b2b commit f6ae717
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/core/streams/openai-stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,24 @@ describe('OpenAIStream', () => {
});

const response = new StreamingTextResponse(stream);
const client = createClient(response);
const chunks = await client.readAll();

await createClient(response).readAll(); // consume stream

expect(toolCalls).toEqual({
tools: [
{
func: {
arguments: '{}',
arguments: {},
name: 'get_date_time',
},
id: 'call_NPkY32jNUOb3Kkm7v9cOgmVg',
type: 'function',
},
{
func: {
arguments: '{"url": "https://www.linkedin.com/in/jessepascoe"}',
arguments: {
url: 'https://www.linkedin.com/in/jessepascoe',
},
name: 'open_webpage',
},
id: 'call_pOyOtXFQltSjUGsF7gnLAEcD',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/streams/openai-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ function createFunctionCallTransformer(
type: 'function',
func: {
name: tool.function.name,
arguments: tool.function.arguments,
arguments: JSON.parse(tool.function.arguments),
},
});
}
Expand Down

0 comments on commit f6ae717

Please sign in to comment.