Skip to content

Commit aab5324

Browse files
authoredMar 4, 2024··
Revert #1065 (#1080)
1 parent fe55612 commit aab5324

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed
 

‎.changeset/khaki-starfishes-fold.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'ai': patch
3+
---
4+
5+
Revert "fix(render): parse the args based on the zod schema"

‎packages/core/rsc/streamable.tsx

+5-32
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ export function render<
182182
[name in keyof TS]: {
183183
description?: string;
184184
parameters: TS[name];
185-
render: Renderer<z.output<TS[name]>>;
185+
render: Renderer<z.infer<TS[name]>>;
186186
};
187187
};
188188
functions?: {
189189
[name in keyof FS]: {
190190
description?: string;
191191
parameters: FS[name];
192-
render: Renderer<z.output<FS[name]>>;
192+
render: Renderer<z.infer<FS[name]>>;
193193
};
194194
};
195195
initial?: ReactNode;
@@ -300,27 +300,6 @@ export function render<
300300
let hasFunction = false;
301301
let content = '';
302302

303-
const parseFunctionCallArguments = (fn: {
304-
type: 'functions' | 'tools';
305-
name: string;
306-
arguments: any;
307-
}) => {
308-
const renderer =
309-
fn.type === 'functions'
310-
? options.functions?.[fn.name]
311-
: options.tools?.[fn.name];
312-
313-
const safeParsed = renderer?.parameters.safeParse(fn.arguments);
314-
315-
if (safeParsed && !safeParsed.success) {
316-
throw new Error(
317-
`Invalid function call arguments in message. ${safeParsed.error.message}`,
318-
);
319-
}
320-
321-
return safeParsed?.data;
322-
};
323-
324303
consumeStream(
325304
OpenAIStream(
326305
(await options.provider.chat.completions.create({
@@ -345,10 +324,7 @@ export function render<
345324
async experimental_onFunctionCall(functionCallPayload) {
346325
hasFunction = true;
347326
handleRender(
348-
parseFunctionCallArguments({
349-
...functionCallPayload,
350-
type: 'functions',
351-
}),
327+
functionCallPayload.arguments,
352328
options.functions?.[functionCallPayload.name as any]
353329
?.render,
354330
ui,
@@ -358,16 +334,13 @@ export function render<
358334
: {}),
359335
...(tools
360336
? {
361-
async experimental_onToolCall(toolCallPayload) {
337+
async experimental_onToolCall(toolCallPayload: any) {
362338
hasFunction = true;
363339

364340
// TODO: We might need Promise.all here?
365341
for (const tool of toolCallPayload.tools) {
366342
handleRender(
367-
parseFunctionCallArguments({
368-
type: 'tools',
369-
...tool.func,
370-
}),
343+
tool.func.arguments,
371344
options.tools?.[tool.func.name as any]?.render,
372345
ui,
373346
);

0 commit comments

Comments
 (0)
Please sign in to comment.