Customisation Examples
Tailor the dice-roller analysis to your specific industry, language, or use case with configuration options.
Configuration Interface
The analysisConfig option allows you to customize how text is analyzed:
interface AnalysisConfig {
// Replace default English stop words
customStopWords?: string[];
// Add industry-specific synonym groups
customSynonyms?: string[][];
// Extend positive sentiment indicators
customPositiveIndicators?: string[];
// Extend negative sentiment indicators
customNegativeIndicators?: string[];
}Non-English Content
By default, the library uses English stop words and sentiment indicators. For other languages, provide your own:
import { analyzeStability } from '@rankfor/dice-roller';
// German language configuration
const germanConfig = {
customStopWords: [
'der', 'die', 'das', 'ein', 'eine', 'und', 'oder', 'aber',
'in', 'auf', 'an', 'zu', 'von', 'mit', 'ist', 'sind', 'war',
'haben', 'hat', 'wird', 'werden', 'kann', 'konnen', 'muss',
'dass', 'wenn', 'weil', 'als', 'auch', 'noch', 'nur', 'sehr',
'mehr', 'schon', 'so', 'wie', 'was', 'wer', 'wo', 'wann',
],
customPositiveIndicators: [
'ausgezeichnet', 'beste', 'fuhrend', 'innovativ', 'experte',
'vertrauenswurdig', 'empfehlen', 'uberlegen', 'hervorragend',
'bewahrt', 'zuverlassig', 'qualitat', 'effektiv', 'effizient',
],
customNegativeIndicators: [
'schlecht', 'mangelhaft', 'unzureichend', 'gescheitert',
'problematisch', 'schwach', 'begrenzt', 'besorgniserregend',
'enttauschend', 'veraltet', 'langsam', 'unzuverlassig',
],
};
const result = await analyzeStability({
prompt: 'Was sind die besten CRM-Tools fur kleine Unternehmen?',
iterations: 5,
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
brandName: 'Salesforce',
analysisConfig: germanConfig,
});Industry-Specific Synonyms
Add synonym groups relevant to your industry so semantically similar terms are grouped together:
// Healthcare / Medical industry
const healthcareConfig = {
customSynonyms: [
['patient', 'client', 'consumer', 'member', 'beneficiary'],
['EHR', 'EMR', 'electronic health record', 'medical record system'],
['telehealth', 'telemedicine', 'virtual care', 'remote healthcare'],
['HIPAA', 'compliance', 'regulatory', 'privacy'],
['outcome', 'result', 'efficacy', 'effectiveness'],
['provider', 'physician', 'doctor', 'clinician', 'healthcare professional'],
['treatment', 'therapy', 'intervention', 'care plan'],
],
};
const result = await analyzeStability({
prompt: 'What are the best EHR systems for small practices?',
iterations: 5,
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
brandName: 'Epic',
analysisConfig: healthcareConfig,
});// Financial Services industry
const financeConfig = {
customSynonyms: [
['ROI', 'return on investment', 'returns', 'yield'],
['AUM', 'assets under management', 'managed assets'],
['compliance', 'regulatory', 'SEC', 'FINRA', 'audit'],
['portfolio', 'holdings', 'investments', 'positions'],
['advisory', 'wealth management', 'financial planning'],
['risk', 'volatility', 'exposure', 'downside'],
['liquidity', 'cash flow', 'working capital'],
],
customPositiveIndicators: [
'fiduciary', 'diversified', 'growth', 'yield', 'outperform',
'alpha', 'low-cost', 'transparent', 'regulated',
],
customNegativeIndicators: [
'volatile', 'illiquid', 'risky', 'overpriced', 'underperform',
'fees', 'hidden costs', 'losses',
],
};// E-commerce / Retail industry
const ecommerceConfig = {
customSynonyms: [
['SKU', 'product', 'item', 'merchandise', 'inventory'],
['cart', 'basket', 'checkout', 'purchase'],
['fulfillment', 'shipping', 'delivery', 'logistics'],
['conversion', 'sale', 'transaction', 'purchase'],
['AOV', 'average order value', 'basket size'],
['return', 'refund', 'exchange', 'RMA'],
['omnichannel', 'multichannel', 'unified commerce'],
],
};Error Handling & Progress
Use callbacks to handle errors and track progress in production applications:
import { analyzeStability, IterationError } from '@rankfor/dice-roller';
const result = await analyzeStability({
prompt: 'Best project management tools',
iterations: 10,
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
// Progress callback
onProgress: (iteration, total) => {
const percent = Math.round((iteration / total) * 100);
console.log(`Progress: ${percent}% (${iteration}/${total})`);
// Update your UI here
},
// Error callback - called for individual iteration failures
onError: (error: IterationError) => {
console.error(`Iteration ${error.iteration} failed: ${error.message}`);
// Log to monitoring service, show user notification, etc.
// Analysis continues with remaining iterations
},
});
// Check how many iterations succeeded
console.log(`Completed ${result.responses.length} of 10 iterations`);// Cross-model experiment with error handling
import { runExperiment } from '@rankfor/dice-roller';
const result = await runExperiment({
prompt: 'Best analytics platforms',
apiKeys: {
geminiApiKey: process.env.GEMINI_API_KEY,
openaiApiKey: process.env.OPENAI_API_KEY,
grokApiKey: process.env.GROK_API_KEY,
},
iterations: 5,
// Progress includes model name
onProgress: (model, iteration, total) => {
console.log(`[${model}] ${iteration}/${total}`);
},
// Error includes model name
onError: (error) => {
console.error(`[${error.model}] Iteration ${error.iteration}: ${error.message}`);
},
});Memory vs Search Mode
Compare what AI "remembers" from training versus what it finds via live web search:
import { analyzeStability } from '@rankfor/dice-roller';
// Memory mode (default) - uses training data only
const memoryResult = await analyzeStability({
prompt: 'Best CRM tools for startups in 2026',
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
searchMode: 'memory',
});
// Search mode - uses live web search
const searchResult = await analyzeStability({
prompt: 'Best CRM tools for startups in 2026',
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
searchMode: 'search',
});
// Compare results
console.log('Memory brand mentions:', memoryResult.brandMentions.average);
console.log('Search brand mentions:', searchResult.brandMentions.average);
// Search mode includes citations
for (const response of searchResult.responses) {
if (response.citations?.length) {
console.log('Sources:', response.citations.map(c => c.url));
}
}Complete Example
Here's a complete example combining multiple customisation options:
import { analyzeStability, AnalysisConfig } from '@rankfor/dice-roller';
// SaaS/B2B Software industry configuration
const saasConfig: AnalysisConfig = {
customSynonyms: [
['SaaS', 'cloud software', 'software as a service', 'cloud-based'],
['MRR', 'monthly recurring revenue', 'subscription revenue'],
['churn', 'attrition', 'customer loss', 'cancellation'],
['onboarding', 'implementation', 'setup', 'deployment'],
['integration', 'API', 'connector', 'plugin'],
['scalable', 'elastic', 'flexible', 'adaptable'],
],
customPositiveIndicators: [
'enterprise-grade', 'scalable', 'intuitive', 'seamless',
'automated', 'AI-powered', 'real-time', 'secure',
],
customNegativeIndicators: [
'legacy', 'clunky', 'manual', 'downtime', 'vendor lock-in',
],
};
async function analyzeCompetitiveLandscape() {
const result = await analyzeStability({
prompt: 'What are the top marketing automation platforms for B2B companies?',
iterations: 7,
model: 'gemini',
apiKey: process.env.GEMINI_API_KEY,
brandName: 'HubSpot',
temperature: 0.8, // Slightly higher for more varied responses
maxTokens: 3000, // Allow longer responses
iterationDelayMs: 1500, // Respect rate limits
searchMode: 'search', // Use live web data
analysisConfig: saasConfig,
onProgress: (iteration, total) => {
process.stdout.write(`\rAnalyzing... ${iteration}/${total}`);
},
onError: (error) => {
console.warn(`\nWarning: Iteration ${error.iteration} failed`);
},
});
console.log('\n\nResults:');
console.log('='.repeat(50));
console.log(`Consistency Score: ${result.consistencyScore}%`);
console.log(`Semantic Overlap: ${result.semanticOverlap}%`);
console.log(`Brand Mentions: avg ${result.brandMentions.average}`);
console.log(`Estimated Tokens: ${result.responses.reduce((sum, r) => sum + r.estimatedTokens, 0)}`);
console.log('\nCore Messages (always mentioned):');
result.analysis.coreStableMessages.forEach(msg => console.log(` - ${msg}`));
console.log('\nVariable Messages (sometimes mentioned):');
result.analysis.variableMessages.forEach(vm =>
console.log(` - ${vm.message} (${vm.frequency}%)`)
);
return result;
}
analyzeCompetitiveLandscape().catch(console.error);