Advanced
Text Generation Options

Text Generation Options

Model Configuration Options

OptionTypeDefaultDescription
quantizationstringq4f16_1Model quantization level ('q4f16_1', 'q4f32_1', 'q0f32', 'q0f16')
onProgressfunction-Callback for loading progress updates
onCompletefunction-Callback when loading completes
onErrorfunction-Callback for error handling

Generation Parameters

ParameterTypeDefaultDescription
temperaturenumber0.7Controls randomness (0.0 - 1.0)
maxTokensnumber100Maximum length of response
topPnumber0.9Nucleus sampling parameter
topKnumber40Top-k sampling parameter
system_promptstring-System prompt for context
stop_tokensstring[][]Tokens that stop generation
context_windownumber2048Maximum context size

Example

import { BrowserAI } from '@browserai/browserai';
const browserAI = new BrowserAI();
 
// Load model with advanced options
await browserAI.loadModel('llama-3.2-1b-instruct', {
  quantization: 'q4f16_1',
  onProgress: (progress) => {
    console.log('Loading progress:', progress.progress + '%');
    // "Loading progress: 45%"
  },
  onComplete: () => {
    console.log('Status:', 'Ready to generate!'); // "Status: Ready to generate!"
  }
});
 
// Generate text with custom parameters
const response = await browserAI.generateText('Write a story about AI', {
  temperature: 0.8,
  maxTokens: 200,
  topP: 0.9,
  topK: 40,
  system_prompt: "You are a creative storyteller specialized in science fiction.",
  stop_tokens: ["\n\n", "THE END"],
  context_window: 2048
});
 
console.log('Generated Story:', response); // "In the year 2045..."