Documentation
Functions
createAIExtractFunction

Function: createAIExtractFunction()

createAIExtractFunction<Schema>(__namedParameters, customExtractImplementation?): ExtractFunction<Schema>

Use OpenAI function calling to extract data from a message.

Type parameters

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

Parameters

ParameterTypeDescription
__namedParametersobject-
__namedParameters.chatModelChatModelThe ChatModel used to make API calls.
__namedParameters.context?CtxOptional context to pass to ChatModel.run calls
__namedParameters.description?stringThe description of the extractor function.
__namedParameters.functionCallConcurrency?numberThe number of function calls to make concurrently.
__namedParameters.maxRetries?numberThe maximum number of times to retry the function call.
__namedParameters.name?stringThe name of the extractor function.
__namedParameters.params?Partial<Omit<Run & Config, "messages" | "functions" | "tools">>Model params to use for each API call (optional).
__namedParameters.schema?SchemaThe Zod schema for the data to extract.
__namedParameters.systemMessage?stringAdd a system message to the beginning of the messages array.
customExtractImplementation?(params) => TypeOf<Schema> | Promise<TypeOf<Schema>>Optional custom extraction function to call with the parsed arguments.

This is useful for adding custom validation to the extracted data.

Returns

ExtractFunction<Schema>

Source

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