Text Generation Example
Learn how to generate text using different models and parameters with Lumia AI.
Code
Complete implementation with comments
import { generateText } from 'ai';
import { Lumia } from '@ai-sdk/Lumia';
// Basic text generation
async function generateBasicText() {
const { text } = await generateText({
model: Lumia('Lumia-V2-Pro'),
prompt: 'Write a short story about AI',
system: 'You are a creative writer.'
});
console.log(text);
}
generateBasicText();
Parameters Explained
Understanding the available configuration options
Temperature
Controls randomness in the output. Higher values (e.g., 0.8) make the output more creative, while lower values (e.g., 0.2) make it more focused and deterministic.
Max Tokens
The maximum length of the generated text. One token is roughly 4 characters of English text.
Top P
An alternative to temperature, controls diversity via nucleus sampling. Lower values (e.g., 0.1) make the output more focused.
Frequency Penalty
Reduces repetition by penalizing tokens based on their frequency in the text so far.