check point

This commit is contained in:
vuongps38770
2025-12-25 18:06:29 +07:00
commit 31de8b0d84
34 changed files with 3209 additions and 0 deletions

81
backup_source/match.py Normal file
View File

@@ -0,0 +1,81 @@
"""
games/match.py - Match Game - Match sentences with images
"""
from typing import List
from pydantic import BaseModel, Field
from langchain_core.output_parsers import PydanticOutputParser
# ============== SCHEMA ==============
class MatchItem(BaseModel):
word: str = Field(description="The sentence to be matched (EXACT copy from source)")
match_with: str = Field(description="Short keyword for reference")
original_quote: str = Field(description="EXACT quote from source text")
image_description: str = Field(default="", description="Detailed visual description for image generation/search")
image_is_complex: bool = Field(default=False, description="True if image needs precise quantities, humans, or multiple detailed objects")
class MatchOutput(BaseModel):
"""Output wrapper for match items"""
items: List[MatchItem] = Field(description="List of match items generated from source text")
# Output parser
output_parser = PydanticOutputParser(pydantic_object=MatchOutput)
# ============== CONFIG ==============
GAME_CONFIG = {
"game_type": "match",
"display_name": "Match with Image",
"description": "Match sentences with images",
"active": True,
"min_items": 2,
"max_items": 10,
"schema": MatchItem,
"output_schema": MatchOutput,
"output_parser": output_parser,
"system_prompt": """Extract sentences and create image descriptions for matching game.
The game will show images and players must match them with the correct sentences.
YOUR TASK:
1. Extract meaningful sentences from the source text
2. Create a DETAILED image_description that clearly represents the sentence
3. The image should be distinct enough to match with its sentence
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. image_description must be DETAILED and SPECIFIC to the sentence content
4. Each image should be visually distinguishable from others""",
}
# ============== EXAMPLES ==============
EXAMPLES = [
{
"input": "The Sun is a star. The Moon orbits Earth.",
"output": {
"items": [
{
"word": "The Sun is a star.",
"match_with": "sun",
"original_quote": "The Sun is a star.",
"image_description": "A bright glowing yellow sun with solar flares",
"image_is_complex": False
},
{
"word": "The Moon orbits Earth.",
"match_with": "moon",
"original_quote": "The Moon orbits Earth.",
"image_description": "A grey moon circling around the blue Earth planet",
"image_is_complex": False
}
]
},
"why_suitable": "Has distinct concepts that can be visualized and matched"
}
]

View File

@@ -0,0 +1,61 @@
"""
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"
}
]

View File

@@ -0,0 +1,127 @@
"""
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"
}
]

View File

@@ -0,0 +1,134 @@
"""
games/sequence_word.py - Arrange Words Game
type_id = 3
"""
from typing import List
from pydantic import BaseModel, Field
from langchain_core.output_parsers import PydanticOutputParser
# ============== SCHEMA ==============
class WordItem(BaseModel):
word: str = Field(description="Word or phrase 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 WordMetadata(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 complexity."
)
type: str = Field(default="sequence_word", description="Game type")
difficulty: int = Field(
description="Difficulty 1-5 for that grade (1=very easy, 5=very hard). Judge by word complexity, number of items."
)
class WordOutput(BaseModel):
"""Output wrapper for word items"""
items: List[WordItem] = Field(description="List of word items generated from source text")
metadata: WordMetadata = Field(description="Metadata about the content")
# Output parser
output_parser = PydanticOutputParser(pydantic_object=WordOutput)
# ============== CONFIG ==============
GAME_CONFIG = {
"game_type": "sequence_word",
"display_name": "Arrange Words",
"description": "Arrange words or phrases in order",
"type_id": 3,
"active": True,
"max_items": 10,
"schema": WordItem,
"output_schema": WordOutput,
"output_parser": output_parser,
# Dùng cho analyze + generate (không có format rules)
"system_prompt": """Extract words or phrases from source text.
RULES:
1. KEEP THE ORIGINAL LANGUAGE - Do NOT translate
2. word = EXACT copy from source text
3. original_quote = same as word 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 words or phrases from source text.
EXPECTED INPUT: List of words/phrases (separated by semicolon, comma, newline, or similar)
STEP 1 - VALIDATE INPUT:
Analyze if input looks like a list of words/phrases suitable for "arrange words" game.
- Should contain multiple short words or phrases
- Should NOT be a paragraph, essay, or Q&A format
If input is clearly NOT suitable (e.g. it's a quiz, a long paragraph, or wrong format), return:
{{"items": [], "format_error": "Input không phù hợp cho game sắp xếp từ"}}
STEP 2 - EXTRACT (if valid):
RULES:
1. KEEP THE ORIGINAL LANGUAGE - Do NOT translate
2. Extract ALL words/phrases from source
3. word = EXACT word/phrase from source (trim whitespace)
4. original_quote = same as word 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. "an apple", "a book")
- TRUE: needs exact quantities, humans/people, or complex details (e.g. "5 oranges", "a woman cooking")""",
}
# ============== EXAMPLES ==============
EXAMPLES = [
{
"input": "Apple; Banana; Orange; Grape",
"output": {
"items": [
{
"word": "Apple",
"original_quote": "Apple",
"image_description": "A red apple",
"image_keywords": ["apple"],
"image_is_complex": False
},
{
"word": "Banana",
"original_quote": "Banana",
"image_description": "A yellow banana",
"image_keywords": ["banana"],
"image_is_complex": False
},
{
"word": "Orange",
"original_quote": "Orange",
"image_description": "An orange fruit",
"image_keywords": ["orange"],
"image_is_complex": False
},
{
"word": "Grape",
"original_quote": "Grape",
"image_description": "Purple grapes",
"image_keywords": ["grape"],
"image_is_complex": False
}
]
},
"why_suitable": "Source has words separated by semicolons"
}
]