Generative & RagText

Text Generation

Generate natural language content using AI with flexible input methods - from simple prompts to structured message sequences.

Basic Generation

When you need to generate text content from a simple prompt, use .generate.text(). This is useful for creating content like explanations, summaries, or reports. Learn more about basic text generation.

const {
  data: { payload }
} = await unbody.generate
                .text("Explain AI's impact on healthcare");

Generation with Options

Sometimes you need more control over the generated content. Use options like temperature and token limits to fine-tune the output style and length. Learn more about Options

const {
  data: { payload }
} = await unbody.generate
                .text("Write a report on climate change", {
                  model: "gpt-4",
                  topP: 0.7,
                  maxTokens: 1000,
                  temperature: 0.7,
                  presencePenalty: 0,
                  frequencyPenalty: 0
                });

Multi-Message Generation

When you need to send role-based messages array as a prompt, use Message-Based Input. This approach helps when providing system instructions or creating multi-turn conversations with different roles. This works particularly well for creating expert personas or maintaining specific conversation contexts.

const {
  data: { payload }
} = await unbody.generate
                .text([
                  {
                    role: "system",
                    content: "You are an expert on AI"
                  },
                  {
                    role: "user",
                    content: "What are the latest AI trends in 2024?"
                  }
                ], {
                  model: "gpt-4",
                  topP: 0.7,
                  maxTokens: 1000,
                  temperature: 0.7,
                  presencePenalty: 0,
                  frequencyPenalty: 0
                });

Learn more about text generation in detail in our Text Generation Guide.

©2024 Unbody