feaet: rename AIFunction.impl to AIFunction.execute

pull/700/head
Travis Fischer 2025-03-20 20:53:48 +08:00
rodzic a7301087b9
commit 2da5a84615
10 zmienionych plików z 11 dodań i 11 usunięć

Wyświetl plik

@ -14,7 +14,7 @@ export function createAISDKTools(...aiFunctionLikeTools: AIFunctionLike[]) {
tool({ tool({
description: fn.spec.description, description: fn.spec.description,
parameters: fn.inputSchema, parameters: fn.inputSchema,
execute: fn.impl execute: fn.execute
}) })
]) ])
) )

Wyświetl plik

@ -82,7 +82,7 @@ export function createAIFunction<InputSchema extends z.ZodObject<any>, Output>(
type: 'function', type: 'function',
strict strict
} }
aiFunction.impl = ( aiFunction.execute = (
params: z.infer<InputSchema> params: z.infer<InputSchema>
): types.MaybePromise<Output> => { ): types.MaybePromise<Output> => {
return implementation(params) return implementation(params)

Wyświetl plik

@ -75,7 +75,7 @@ export interface AIFunction<
Output = any Output = any
> { > {
/** /**
* Invokes the underlying AI function `impl` but first validates the input * Invokes the underlying AI function `execute` but first validates the input
* against this function's `inputSchema`. This method is callable and is * against this function's `inputSchema`. This method is callable and is
* meant to be passed the raw LLM JSON string or an OpenAI-compatible Message. * meant to be passed the raw LLM JSON string or an OpenAI-compatible Message.
*/ */
@ -94,7 +94,7 @@ export interface AIFunction<
* The underlying function implementation without any arg parsing or validation. * The underlying function implementation without any arg parsing or validation.
*/ */
// TODO: this `any` shouldn't be necessary, but it is for `createAIFunction` results to be assignable to `AIFunctionLike` // TODO: this `any` shouldn't be necessary, but it is for `createAIFunction` results to be assignable to `AIFunctionLike`
impl: (params: z.infer<InputSchema> | any) => MaybePromise<Output> execute: (params: z.infer<InputSchema> | any) => MaybePromise<Output>
} }
export type SafeParseResult<TData> = export type SafeParseResult<TData> =

Wyświetl plik

@ -264,7 +264,7 @@ export function isAIFunction(obj: any): obj is types.AIFunction {
if (!obj.inputSchema) return false if (!obj.inputSchema) return false
if (!obj.parseInput) return false if (!obj.parseInput) return false
if (!obj.spec) return false if (!obj.spec) return false
if (!obj.impl) return false if (!obj.execute) return false
if (!obj.spec.name || typeof obj.spec.name !== 'string') return false if (!obj.spec.name || typeof obj.spec.name !== 'string') return false
return true return true

Wyświetl plik

@ -17,7 +17,7 @@ export function createDexterFunctions(
description: fn.spec.description, description: fn.spec.description,
argsSchema: fn.inputSchema argsSchema: fn.inputSchema
}, },
fn.impl fn.execute
) )
) )
} }

Wyświetl plik

@ -20,7 +20,7 @@ export function createGenkitTools(
inputSchema: fn.inputSchema, inputSchema: fn.inputSchema,
outputSchema: z.any() outputSchema: z.any()
}, },
fn.impl fn.execute
) )
) )
} }

Wyświetl plik

@ -19,7 +19,7 @@ export function createLangChainTools(...aiFunctionLikeTools: AIFunctionLike[]) {
description: fn.spec.description, description: fn.spec.description,
schema: fn.inputSchema, schema: fn.inputSchema,
func: async (input) => { func: async (input) => {
const result = await Promise.resolve(fn.impl(input)) const result = await Promise.resolve(fn.execute(input))
// LangChain tools require the output to be a string // LangChain tools require the output to be a string
return stringifyForModel(result) return stringifyForModel(result)
} }

Wyświetl plik

@ -11,7 +11,7 @@ export function createLlamaIndexTools(
const fns = new AIFunctionSet(aiFunctionLikeTools) const fns = new AIFunctionSet(aiFunctionLikeTools)
return fns.map((fn) => return fns.map((fn) =>
FunctionTool.from(fn.impl, { FunctionTool.from(fn.execute, {
name: fn.spec.name, name: fn.spec.name,
description: fn.spec.description, description: fn.spec.description,
parameters: fn.spec.parameters as any parameters: fn.spec.parameters as any

Wyświetl plik

@ -15,7 +15,7 @@ export function createMastraTools(...aiFunctionLikeTools: AIFunctionLike[]) {
id: fn.spec.name, id: fn.spec.name,
description: fn.spec.description, description: fn.spec.description,
inputSchema: fn.inputSchema, inputSchema: fn.inputSchema,
execute: (ctx) => fn.impl(ctx.context) execute: (ctx) => fn.execute(ctx.context)
}) })
]) ])
) )

Wyświetl plik

@ -16,7 +16,7 @@ export function createXSAITools(
name: fn.spec.name, name: fn.spec.name,
description: fn.spec.description, description: fn.spec.description,
parameters: fn.inputSchema, parameters: fn.inputSchema,
execute: fn.impl execute: fn.execute
}) })
) )
) )