Documentation
Functions
Createaifunction

Function: createAIFunction()

createAIFunction<Schema, Return>(spec, implementation): AIFunction<Schema, Return>

Create a function meant to be used with OpenAI tool or function calling.

The returned function will parse the arguments string and call the implementation function with the parsed arguments.

The spec property of the returned function is the spec for adding the function to the OpenAI API functions property.

Type parameters

Parameter
Schema extends ZodObject<any, UnknownKeysParam, ZodTypeAny, object, object>
Return extends unknown

Parameters

ParameterTypeDescription
specobject-
spec.argsSchemaSchemaZod schema for the arguments string.
spec.description?stringDescription of the function.
spec.namestringName of the function.
implementation(params) => Promise<Return>Implementation of the function to call with the parsed arguments.

Returns

AIFunction<Schema, Return>

Source

src/prompt/functions/ai-function.ts:16 (opens in a new tab)