62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""
|
|
games/memory_card.py - Memory Card Game - Flip cards to find pairs
|
|
"""
|
|
from typing import List
|
|
from pydantic import BaseModel, Field
|
|
from langchain_core.output_parsers import PydanticOutputParser
|
|
|
|
|
|
# ============== SCHEMA ==============
|
|
class MemoryCardItem(BaseModel):
|
|
name: str = Field(description="Card content/label")
|
|
pair_id: str = Field(description="ID to match pairs (same pair_id = matching cards)")
|
|
original_quote: str = Field(description="EXACT quote from source text")
|
|
image_description: str = Field(default="", description="Visual description for the card")
|
|
image_is_complex: bool = Field(default=False, description="True if image needs precise quantities, humans, or multiple detailed objects")
|
|
|
|
|
|
class MemoryCardOutput(BaseModel):
|
|
"""Output wrapper for memory card items"""
|
|
items: List[MemoryCardItem] = Field(description="List of memory card items generated from source text")
|
|
|
|
|
|
# Output parser
|
|
output_parser = PydanticOutputParser(pydantic_object=MemoryCardOutput)
|
|
|
|
|
|
# ============== CONFIG ==============
|
|
GAME_CONFIG = {
|
|
"game_type": "memory_card",
|
|
"display_name": "Memory Card",
|
|
"description": "Flip cards to find pairs",
|
|
|
|
"active": False, # Disabled
|
|
|
|
"min_items": 4,
|
|
"max_items": 10,
|
|
"schema": MemoryCardItem,
|
|
"output_schema": MemoryCardOutput,
|
|
"output_parser": output_parser,
|
|
|
|
"system_prompt": """Create memory card pairs.
|
|
CRITICAL RULES:
|
|
1. KEEP THE ORIGINAL LANGUAGE - Do NOT translate the source text
|
|
2. original_quote MUST be an EXACT copy from source text
|
|
3. ALL content must come from the source text only""",
|
|
}
|
|
|
|
|
|
# ============== EXAMPLES ==============
|
|
EXAMPLES = [
|
|
{
|
|
"input": "The Sun is a star.",
|
|
"output": {
|
|
"items": [
|
|
{"name": "The Sun", "pair_id": "p1", "original_quote": "The Sun is a star.", "image_description": "A bright sun", "image_is_complex": False},
|
|
{"name": "a star", "pair_id": "p1", "original_quote": "The Sun is a star.", "image_description": "A glowing star", "image_is_complex": False}
|
|
]
|
|
},
|
|
"why_suitable": "Has concept pairs"
|
|
}
|
|
]
|