UNPKG

@ai-stack/payloadcms

Version:

<p align="center"> <img alt="Payload AI Plugin" src="assets/payload-ai-intro.gif" width="100%" /> </p>

40 lines (35 loc) 1.48 kB
import { jsonSchema, streamObject } from 'ai'; import { openai } from './openai.js'; export const generateRichText = (text, options = {})=>{ const streamResult = streamObject({ maxTokens: options.maxTokens || 5000, model: openai(options.model, { structuredOutputs: true }), onError: (error)=>{ console.error(`generateRichText: `, error); }, prompt: text, schema: jsonSchema(options.editorSchema), system: `${options.system} RULES: - Generate original and unique content based on the given topic. - Strictly adhere to the specified layout and formatting instructions. - Utilize the provided rich text editor tools for appropriate formatting. - Ensure the output follows the structure of the sample output object. - Produce valid JSON with no undefined or null values. LAYOUT INSTRUCTIONS: ${options.layout} RICH TEXT EDITOR TOOLS: - Use appropriate formatting tools such as bold, italic, or underline for emphasis where needed. - Apply correct heading levels (h1, h2, h3) for hierarchical structure. - Utilize bullet points or numbered lists as required by the layout. ADDITIONAL GUIDELINES: - Ensure coherence and logical flow between all sections. - Maintain a consistent tone and style throughout the content. - Use clear and concise language appropriate for the target audience. ` }); return streamResult.toTextStreamResponse(); }; //# sourceMappingURL=generateRichText.js.map