Skip to content

Commit

Permalink
feat: tools without execute function (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 13, 2024
1 parent 852ee54 commit 376bc63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react/src/runtimes/edge/streams/toolResultStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function toolResultStream(tools: Record<string, Tool> | 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) {
Expand All @@ -43,7 +43,7 @@ export function toolResultStream(tools: Record<string, Tool> | undefined) {
toolCallId,
(async () => {
try {
const result = await tool.execute(args);
const result = await tool.execute!(args);

controller.enqueue({
type: "tool-result",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/types/ModelConfigTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ToolExecuteFunction<TArgs, TResult> = (
export type Tool<TArgs = unknown, TResult = unknown> = {
description?: string | undefined;
parameters: z.ZodSchema<TArgs> | JSONSchema7;
execute: ToolExecuteFunction<TArgs, TResult>;
execute?: ToolExecuteFunction<TArgs, TResult>;
};

export type ModelConfig = {
Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

0 comments on commit 376bc63

Please sign in to comment.