""" games/sequence_sentence.py - Arrange Sentences Game type_id = 2 """ from typing import List from pydantic import BaseModel, Field from langchain_core.output_parsers import PydanticOutputParser # ============== SCHEMA ============== class SentenceItem(BaseModel): sentence: str = Field(description="Full sentence to arrange (EXACT from source)") original_quote: str = Field(description="EXACT quote from source text") image_description: str = Field(default="", description="Visual description of the content") image_keywords: List[str] = Field(default=[], description="Keywords for image search") image_is_complex: bool = Field(default=False, description="True if image needs precise quantities, humans, or multiple detailed objects") class SentenceMetadata(BaseModel): """Metadata đánh giá nội dung""" title: str = Field( description="Title for this content. Prefer title from source document if available and suitable, otherwise create a short descriptive title." ) description: str = Field( description="Short description summarizing the content/topic." ) grade: int = Field( description="Estimated grade level 1-5 (1=easy/young, 5=advanced/older). Judge by vocabulary, concepts." ) type: str = Field(default="sequence_sentence", description="Game type") difficulty: int = Field( description="Difficulty 1-5 for that grade (1=very easy, 5=very hard). Judge by sentence complexity, vocabulary." ) class SentenceOutput(BaseModel): """Output wrapper for sentence items""" items: List[SentenceItem] = Field(description="List of sentence items generated from source text") metadata: SentenceMetadata = Field(description="Metadata about the content") # Output parser output_parser = PydanticOutputParser(pydantic_object=SentenceOutput) # ============== CONFIG ============== GAME_CONFIG = { "game_type": "sequence_sentence", "display_name": "Arrange Sentences", "description": "Arrange sentences in order", "type_id": 2, "active": True, "max_items": 10, "schema": SentenceItem, "output_schema": SentenceOutput, "output_parser": output_parser, # Dùng cho analyze + generate (không có format rules) "system_prompt": """Extract sentences from source text. RULES: 1. KEEP THE ORIGINAL LANGUAGE - Do NOT translate 2. sentence = EXACT copy from source text 3. original_quote = same as sentence value 4. image_description = ALWAYS provide a short visual description (NEVER empty) 5. image_is_complex = FALSE for simple/static objects, TRUE for quantities/humans/complex scenes""", # Dùng cho generate trực tiếp (CÓ format rules) "direct_prompt": """Extract sentences from source text. EXPECTED INPUT: List of sentences (separated by semicolon, newline, or similar) STEP 1 - VALIDATE INPUT: Analyze if input looks like a list of sentences suitable for "arrange sentences" game. - Should contain multiple complete sentences - Should NOT be a quiz, single word list, or Q&A format If input is clearly NOT suitable (e.g. it's a quiz, single words only, or wrong format), return: {{"items": [], "format_error": "Input không phù hợp cho game sắp xếp câu"}} STEP 2 - EXTRACT (if valid): RULES: 1. KEEP THE ORIGINAL LANGUAGE - Do NOT translate 2. Extract ALL sentences from source 3. sentence = EXACT sentence from source (trim whitespace) 4. original_quote = same as sentence value 5. image_description = ALWAYS provide a short visual description (NEVER leave empty) 6. image_is_complex: - FALSE: simple objects, static things, no specific quantities (e.g. "a sun", "a tree") - TRUE: needs exact quantities, humans/people, or complex details (e.g. "3 birds", "a boy reading")""", } # ============== EXAMPLES ============== EXAMPLES = [ { "input": "The Sun is a star; The Moon orbits Earth; Mars is red", "output": { "items": [ { "sentence": "The Sun is a star", "original_quote": "The Sun is a star", "image_description": "A bright glowing sun", "image_keywords": ["sun", "star"], "image_is_complex": False }, { "sentence": "The Moon orbits Earth", "original_quote": "The Moon orbits Earth", "image_description": "Moon circling around Earth", "image_keywords": ["moon", "earth", "orbit"], "image_is_complex": False }, { "sentence": "Mars is red", "original_quote": "Mars is red", "image_description": "Red planet Mars", "image_keywords": ["mars", "red", "planet"], "image_is_complex": False } ] }, "why_suitable": "Source has sentences separated by semicolons" } ]