AI-Powered Features

Harness the power of AI to create personas from natural language, select optimal distributions, and generate deep insights about your persona groups.

Create from Prompt

Generate complete personas from natural language descriptions:

ai-prompt-example.ts
1const persona = await PersonaBuilder.fromPrompt(
2 'Create a 25-year-old software developer who enjoys gaming',
3 { apiKey: process.env.OPENAI_API_KEY }
4);
5
6// Result:
7// {
8// name: 'Marcus Chen',
9// age: 25,
10// occupation: 'Software Developer',
11// hobbies: ['gaming', 'coding', 'tech blogs'],
12// personality: 'analytical, creative, introverted'
13// }

Structured Output

Extract structured insights from persona groups using Zod schemas:

structured-output.ts
1import { z } from 'zod';
2
3const MarketInsightSchema = z.object({
4 targetSegment: z.string(),
5 topInterests: z.array(z.string()),
6 recommendations: z.array(z.string())
7});
8
9const insights = await group.generateStructuredOutput(
10 MarketInsightSchema,
11 'Analyze this audience for marketing'
12);

Distribution Selection

AI automatically selects the best statistical distribution for your data based on context.

import { DistributionSelector } from '@jamesaphoenix/persona-sdk';
const selector = new DistributionSelector({ apiKey: process.env.OPENAI_API_KEY });
const result = await selector.selectDistribution({
attribute: 'income',
context: 'Tech startup employees in Silicon Valley',
constraints: { min: 50000, max: 200000 }
});
// Result: {
// type: 'normal',
// params: { mean: 120000, stdDev: 25000 },
// reasoning: 'Normal distribution fits tech salaries...'
// }

Media-to-Persona

Generate personas from images, videos, or audio content analysis.

import { MediaToPersonaGenerator } from '@jamesaphoenix/persona-sdk';
const generator = new MediaToPersonaGenerator();
// From image
const personas = await generator.fromImage('./lifestyle-photo.jpg');
// From video
const personas = await generator.fromVideo('./customer-interview.mp4');
// From audio
const personas = await generator.fromAudio('./podcast-segment.mp3');
console.log(personas[0].attributes);
// { age: 28, lifestyle: 'urban professional', interests: ['fitness', 'technology'] }

Focus Groups

Simulate focus group discussions with diverse persona perspectives.

import { FocusGroupSimulator } from '@jamesaphoenix/persona-sdk';
const simulator = new FocusGroupSimulator();
const discussion = await simulator.simulate({
personas: techStartupGroup,
topic: 'New mobile app features',
duration: '30 minutes',
moderatorStyle: 'structured'
});
console.log(discussion.transcript);
// [
// { speaker: 'Alice (Designer)', message: 'I think the UI should be...' },
// { speaker: 'Bob (Engineer)', message: 'From a technical standpoint...' }
// ]

LangChain Integration

Build complex AI pipelines with LangChain compatibility.

import { PersonaChain } from '@jamesaphoenix/persona-sdk';
import { ChatOpenAI } from 'langchain/chat_models/openai';
const chain = new PersonaChain({
llm: new ChatOpenAI({ temperature: 0.7 }),
personas: marketingGroup
});
const result = await chain.invoke({
input: 'Analyze market reaction to product launch',
outputSchema: MarketAnalysisSchema
});
// Integrates seamlessly with LangChain pipelines
const pipeline = chain.pipe(analysisChain).pipe(reportChain);

⚡ Performance Tip

Use environment variables for API keys and consider caching AI-generated personas to reduce API costs.