UNPKG

ai-functions

Version:

A powerful TypeScript library for building AI-powered applications with template literals and structured outputs

29 lines 973 B
import { stringify } from 'yaml'; import { generateObject, streamObject } from '@/index'; function generatePrompt(functionName, args) { const yamlArgs = stringify(args, { flowLevel: 1 }); return `${functionName}:\n${yamlArgs}`; } export function createAIFunction(functionName, schema, options = {}) { return async function (input) { const { seed, ...restInput } = input; // Extract seed from input const prompt = generatePrompt(functionName, restInput); const baseOptions = { schema, prompt, model: options.model || 'gpt-4-turbo', system: options.system, seed // Pass seed to AI functions }; if (options.stream) { return streamObject({ ...baseOptions }); } return generateObject({ ...baseOptions, output: 'single' }); }; } //# sourceMappingURL=function-generator.js.map