xiaohongshu
xiaohongshu
convex-ai-card-generation
Generate Pictionary drawing cards using AI (Groq) with fallback to hardcoded libraries. Use when creating new game cards, implementing category-based card selection, or handling AI card generation with graceful degradation.
Full skill instructions
This skill handles AI-powered card generation for PictionAI's Pictionary gameplay. Cards are generated dynamically using Groq LLM with Vercel AI SDK's generateText function, including structured output validation via Zod schemas and automatic fallback to hardcoded card libraries when API limits are reached.
1. Request card for category
↓
2. Check card availability/balance
↓
3. Try Groq (primary) → Fallback to other models → Fallback to hardcoded library
↓
4. Validate with Zod schema
↓
5. Return structured card object { word, description, difficulty, category }
Generate one or multiple drawing cards for a specific category with AI.
action generateCards {
args: {
category: "animals" | "objects" | "actions" | "movies" | "sports",
count?: number // Default: 1, Max: 5
}
// Returns:
// {
// cards: Array<{
// word: string,
// description: string,
// difficulty: "easy" | "medium" | "hard",
// category: string
// }>,
// source: "ai" | "fallback" // Indicates if AI or hardcoded
// }
}
interface Card {
word: string; // Single word to draw (required)
description: string; // Drawing hints/clues (1-100 chars)
difficulty: "easy" | "medium" | "hard";
category: string; // Category name
created_at?: number; // Timestamp
ai_generated?: boolean; // True if from Groq
}
const groq = new Groq({
apiKey: env.GROQ_API_KEY, // Environment variable
baseURL: "https://api.groq.com/openai/v1",
});
const cardSchema = z.object({
word: z.string().min(1).max(30),
description: z.string().min(10).max(100),
difficulty: z.enum(["easy", "medium", "hard"]),
category: z.string(),
});
const cardsResponseSchema = z.object({
cards: z.array(cardSchema),
});
Generate {count} unique Pictionary drawing cards for the "{category}" category.
For each card, provide:
- word: A single word to draw
- description: A brief hint (1-100 characters)
- difficulty: easy, medium, or hard
- category: {category}
Format as JSON array. Make words creative and diverse.
When all AI models fail, the system falls back to hardcoded libraries:
const cardLibraries = {
animals: [
{
word: "elephant",
description: "Large animal with long trunk",
difficulty: "easy",
category: "animals",
},
{
word: "giraffe",
description: "Tall with spotted pattern",
difficulty: "easy",
category: "animals",
},
// ... more animals
],
objects: [
{
word: "bicycle",
description: "Two-wheeled vehicle",
difficulty: "easy",
category: "objects",
},
// ... more objects
],
// ... other categories
};
// In game setup, generate initial card
const generateCardsAction = useAction(api.actions.generateCards);
async function setupGameCards(category: string) {
const result = await generateCardsAction({
category,
count: 5, // Generate 5 cards per round
});
console.log(`Cards generated from ${result.source}`);
return result.cards;
}
console.log(`Generated cards from ${source} for category: ${category}`);
// source: "ai" or "fallback"
✅ Generate multiple cards at game start (not per turn) ✅ Cache cards for session duration ✅ Log both AI and fallback usage for monitoring ✅ Validate all AI responses against Zod schema ✅ Handle quota errors gracefully
❌ Don't wait for card generation on each turn ❌ Don't expose Groq API key in frontend ❌ Don't retry forever on network errors ❌ Don't mix AI and fallback for same category in single game
// Game initialization
export const initializeGameCards = action({
args: { game_id: v.id("games"), category: v.string() },
handler: async (ctx, args) => {
const generateCards = await ctx.runAction(api.actions.generateCards, {
category: args.category,
count: 10,
});
// Store cards in game doc
await ctx.runMutation(api.mutations.games.storeGameCards, {
game_id: args.game_id,
cards: generateCards.cards,
});
return {
count: generateCards.cards.length,
source: generateCards.source,
};
},
});
convex/actions/generateCards.ts - Complete action implementationxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience