Skip to content

Commit

Permalink
breaking(js/ai): drop ToolDefinition from ToolArgument (and generate …
Browse files Browse the repository at this point in the history
…action interface) (#1832)
  • Loading branch information
pavelgj authored Feb 5, 2025
1 parent 6bfa924 commit 59e9ecc
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion genkit-tools/common/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const GenerateActionOptionsSchema = z.object({
/** Conversation history for multi-turn prompting when supported by the underlying model. */
messages: z.array(MessageSchema),
/** List of registered tool names for this generation if supported by the underlying model. */
tools: z.array(z.union([z.string(), ToolDefinitionSchema])).optional(),
tools: z.array(z.string()).optional(),
/** Tool calling mode. `auto` lets the model decide whether to use tools, `required` forces the model to choose a tool, and `none` forces the model not to use any tools. Defaults to `auto`. */
toolChoice: z.enum(['auto', 'required', 'none']).optional(),
/** Configuration for the generation request. */
Expand Down
9 changes: 1 addition & 8 deletions genkit-tools/genkit-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,7 @@
"tools": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string"
},
{
"$ref": "#/$defs/ToolDefinition"
}
]
"type": "string"
}
},
"toolChoice": {
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class Chat {
this.requestBase = Promise.resolve({
...(await this.requestBase),
// these things may get changed by tools calling within generate.
tools: response?.request?.tools,
tools: response?.request?.tools?.map((td) => td.name),
toolChoice: response?.request?.toolChoice,
config: response?.request?.config,
});
Expand Down
2 changes: 1 addition & 1 deletion js/ai/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ export const GenerateActionOptionsSchema = z.object({
/** Conversation history for multi-turn prompting when supported by the underlying model. */
messages: z.array(MessageSchema),
/** List of registered tool names for this generation if supported by the underlying model. */
tools: z.array(z.union([z.string(), ToolDefinitionSchema])).optional(),
tools: z.array(z.string()).optional(),
/** Tool calling mode. `auto` lets the model decide whether to use tools, `required` forces the model to choose a tool, and `none` forces the model not to use any tools. Defaults to `auto`. */
toolChoice: z.enum(['auto', 'required', 'none']).optional(),
/** Configuration for the generation request. */
Expand Down
12 changes: 5 additions & 7 deletions js/ai/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,7 @@ export interface ToolConfig<I extends z.ZodTypeAny, O extends z.ZodTypeAny> {
export type ToolArgument<
I extends z.ZodTypeAny = z.ZodTypeAny,
O extends z.ZodTypeAny = z.ZodTypeAny,
> =
| string
| ToolAction<I, O>
| Action<I, O>
| ToolDefinition
| ExecutablePrompt<any, any, any>;
> = string | ToolAction<I, O> | Action<I, O> | ExecutablePrompt<any, any, any>;

/**
* Converts an action to a tool action by setting the appropriate metadata.
Expand Down Expand Up @@ -162,7 +157,10 @@ export function asTool<I extends z.ZodTypeAny, O extends z.ZodTypeAny>(
export async function resolveTools<
O extends z.ZodTypeAny = z.ZodTypeAny,
CustomOptions extends z.ZodTypeAny = z.ZodTypeAny,
>(registry: Registry, tools?: ToolArgument[]): Promise<ToolAction[]> {
>(
registry: Registry,
tools?: (ToolArgument | ToolDefinition)[]
): Promise<ToolAction[]> {
if (!tools || tools.length === 0) {
return [];
}
Expand Down

0 comments on commit 59e9ecc

Please sign in to comment.