UNPKG

ai-functions

Version:

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

53 lines 2.27 kB
import { createAIFunction, createTemplateFunction } from './factory'; import { createListFunction } from './factory/list'; import { z } from 'zod'; // Create the main template function with async iteration support const templateFn = createTemplateFunction(); // Create the list function with async iteration support const listFn = createListFunction(); // Create the categorizeProduct function with proper schema const categorizeProduct = createAIFunction(z.object({ productType: z.enum(['App', 'API', 'Marketplace', 'Platform', 'Packaged Service', 'Professional Service', 'Website']), customer: z.string().describe('ideal customer profile in 3-5 words'), solution: z.string().describe('describe the offer in 4-10 words'), description: z.string().describe('website meta description'), })); // Create the main AI object with template literal and async iteration support function isTemplateStringsArray(value) { return Array.isArray(value) && 'raw' in value; } function createWrappedTemplateFunction(baseFn) { const wrappedFn = function (stringsOrOptions, ...values) { if (!isTemplateStringsArray(stringsOrOptions)) { return baseFn(values.shift(), ...values, stringsOrOptions); } return baseFn(stringsOrOptions, ...values); }; // Make wrappedFn async iterable by delegating to baseFn Object.defineProperty(wrappedFn, Symbol.asyncIterator, { value: function () { return baseFn[Symbol.asyncIterator](); }, writable: true, configurable: true, }); // Add withOptions method Object.defineProperty(wrappedFn, 'withOptions', { value: (opts) => baseFn.withOptions(opts), writable: true, configurable: true, }); // Add queue property Object.defineProperty(wrappedFn, 'queue', { get: () => baseFn.queue, configurable: true, }); return wrappedFn; } const aiFn = createWrappedTemplateFunction(templateFn); export const ai = Object.assign(aiFn, { categorizeProduct }); // Create the list function with template literal and async iteration support export const list = createWrappedTemplateFunction(listFn); // Export types for consumers export * from './types'; //# sourceMappingURL=index.js.map