Develop and optimize AI prompt strategies for code generation. Use when creating new AI model strategies, optimizing prompts for Claude/GPT/Gemini/DeepSeek/Grok, or improving prompt quality. Includes model-specific optimization techniques.
// lib/prompt-strategies/new-model-strategy.ts
import { BasePromptStrategy } from './base-strategy'
import type { LaydlerSchema, GenerationResult, PromptOptions } from '@/types'
export class NewModelStrategy extends BasePromptStrategy {
constructor(modelId: string) {
super()
this.modelId = modelId
this.modelCapabilities = this.getModelCapabilities(modelId)
}
generatePrompt(
schema: LaydlerSchema,
framework: string,
cssSolution: string,
options?: PromptOptions
): GenerationResult {
const sections: string[] = []
// 1. System prompt (model-specific optimization)
sections.push(this.buildSystemPrompt(options))
// 2. Component specifications
sections.push(this.buildComponentSection(schema.components))
// 3. Layout with canvas grid info
sections.push(this.buildLayoutSection(
schema.components,
schema.breakpoints,
schema.layouts
))
// 4. Model-specific instructions
sections.push(this.buildModelSpecificInstructions(options))
const prompt = sections.join('\n\n---\n\n')
return {
success: true,
prompt,
estimatedTokens: this.estimateTokens(prompt)
}
}
private buildModelSpecificInstructions(options?: PromptOptions): string {
// Model-specific optimizations
if (this.modelCapabilities.supportsChainOfThought && options?.chainOfThought) {
return `
## Reasoning Process
Think through each component step by step:
1. Analyze the semantic tag and its purpose
2. Consider the positioning strategy
3. Plan the layout implementation
4. Generate the code
Show your reasoning before providing the final code.
`
}
return ''
}
}
Step 2: Register in Factory
// lib/prompt-strategies/strategy-factory.ts
import { NewModelStrategy } from './new-model-strategy'
export function createPromptStrategy(modelId: string): BasePromptStrategy {
const provider = getProviderFromModelId(modelId)
switch (provider) {
case 'claude':
return new ClaudeStrategy(modelId)
case 'gpt':
return new GPTStrategy(modelId)
case 'gemini':
return new GeminiStrategy(modelId)
case 'deepseek':
return new DeepSeekStrategy(modelId)
case 'grok':
return new GrokStrategy(modelId)
case 'new-model': // Add new model
return new NewModelStrategy(modelId)
default:
return new BasePromptStrategy(modelId)
}
}
// Extended thinking support for complex layouts
if (options?.optimizationLevel === 'quality') {
systemPrompt += `
<thinking>
Before generating code, analyze:
1. Component hierarchy and relationships
2. Responsive behavior across breakpoints
3. CSS Grid vs Flexbox decision points
4. Accessibility requirements
</thinking>
`
}
GPT Optimization
// O1 reasoning model support
if (modelId.includes('o1')) {
// No system prompt for o1 models
// Use user message with clear structure
return this.buildUserOnlyPrompt(schema, framework, cssSolution)
}
Gemini Optimization
// Structured output preference
instructions += `
## Output Format
Return the code in a structured format:
\`\`\`json
{
"components": [
{
"name": "ComponentName",
"code": "// React component code"
}
],
"layout": "// Main layout component"
}
\`\`\`
`
DeepSeek Optimization
// Code-focused models (Coder V2)
if (modelId.includes('coder')) {
systemPrompt = `You are an expert React/TypeScript developer.
Generate production-ready code following these specifications exactly.
Prioritize code correctness and TypeScript type safety.`
}
Prompt Quality Guidelines
DO Include
## Component Specifications
For each component, specify:
- **Semantic Tag**: The HTML5 semantic element
- **Positioning**: CSS positioning strategy
- **Layout**: Internal layout (flex/grid/container)
- **Canvas Position**: Grid coordinates for visual layout
## Visual Layout (Canvas Grid)
The canvas represents the visual arrangement:
- Grid: 12 columns × 8 rows (desktop)
- Each component has x, y, width, height in grid units
- Use CSS Grid for 2D positioning
- Respect the visual arrangement in generated code
DO NOT Include
❌ DO NOT Generate:
- Theme colors (bg-blue, bg-purple, text-white, gradients)
- Shadows (shadow-sm, shadow-md, shadow-lg)
- Rounded corners (rounded-lg, rounded-xl)
- Demo content or placeholder text with specific styling