From 376bc63ed8effaf78f28ab917d1724a0e87a45a4 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 12 Jul 2024 18:13:36 -0700 Subject: [PATCH] feat: tools without execute function (#481) --- .../react/src/runtimes/edge/streams/toolResultStream.ts | 4 ++-- packages/react/src/types/ModelConfigTypes.ts | 2 +- packages/react/src/types/index.ts | 6 +++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/react/src/runtimes/edge/streams/toolResultStream.ts b/packages/react/src/runtimes/edge/streams/toolResultStream.ts index 0644e343a3..8d3757044d 100644 --- a/packages/react/src/runtimes/edge/streams/toolResultStream.ts +++ b/packages/react/src/runtimes/edge/streams/toolResultStream.ts @@ -27,7 +27,7 @@ export function toolResultStream(tools: Record | undefined) { case "tool-call": { const { toolCallId, toolCallType, toolName, args: argsText } = chunk; const tool = tools?.[toolName]; - if (!tool) return; + if (!tool || !tool.execute) return; const args = sjson.parse(argsText); if (tool.parameters instanceof z.ZodType) { @@ -43,7 +43,7 @@ export function toolResultStream(tools: Record | undefined) { toolCallId, (async () => { try { - const result = await tool.execute(args); + const result = await tool.execute!(args); controller.enqueue({ type: "tool-result", diff --git a/packages/react/src/types/ModelConfigTypes.ts b/packages/react/src/types/ModelConfigTypes.ts index 7c56661763..047a478347 100644 --- a/packages/react/src/types/ModelConfigTypes.ts +++ b/packages/react/src/types/ModelConfigTypes.ts @@ -8,7 +8,7 @@ type ToolExecuteFunction = ( export type Tool = { description?: string | undefined; parameters: z.ZodSchema | JSONSchema7; - execute: ToolExecuteFunction; + execute?: ToolExecuteFunction; }; export type ModelConfig = { diff --git a/packages/react/src/types/index.ts b/packages/react/src/types/index.ts index 338c3ac58a..850eff0adb 100644 --- a/packages/react/src/types/index.ts +++ b/packages/react/src/types/index.ts @@ -34,6 +34,10 @@ export type { ToolCallContentPartComponent, } from "./ContentPartComponentTypes"; -export type { ModelConfig, ModelConfigProvider } from "./ModelConfigTypes"; +export type { + ModelConfig, + ModelConfigProvider, + Tool, +} from "./ModelConfigTypes"; export type { Unsubscribe } from "./Unsubscribe";