init
This commit is contained in:
@@ -1,23 +1,57 @@
|
||||
"""
|
||||
games/match.py - Match Game - Match sentences with images
|
||||
games/match.py - Match Game - Match words/phrases with images
|
||||
type_id = 3
|
||||
|
||||
Input: Danh sách từ hoặc cụm từ
|
||||
Output: Mỗi item gồm từ/cụm từ và mô tả hình ảnh tương ứng
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
from typing import List, Literal
|
||||
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")
|
||||
"""Schema cho 1 item của Match game"""
|
||||
|
||||
word: str = Field(
|
||||
description="The word or phrase to be matched (EXACT copy from source, cleaned of numbering)"
|
||||
)
|
||||
original_quote: str = Field(
|
||||
description="EXACT quote from source text before any cleaning"
|
||||
)
|
||||
image_description: str = Field(
|
||||
description="Detailed visual description for image generation in ENGLISH. Must be specific and visual."
|
||||
)
|
||||
image_keywords: List[str] = Field(
|
||||
default=[], description="2-3 English keywords for image search"
|
||||
)
|
||||
image_is_complex: bool = Field(
|
||||
default=False,
|
||||
description="True if image needs precise quantities, humans, or multiple detailed objects",
|
||||
)
|
||||
|
||||
|
||||
class MatchMetadata(BaseModel):
|
||||
"""Metadata đánh giá nội dung"""
|
||||
|
||||
title: str = Field(description="Title from source or short descriptive title")
|
||||
description: str = Field(description="One sentence summary of the content")
|
||||
grade: int = Field(
|
||||
description="Estimated grade level 1-5 (1=easy/young, 5=advanced)"
|
||||
)
|
||||
type: Literal["match"] = Field(default="match", description="Game type")
|
||||
difficulty: int = Field(description="Difficulty 1-5 for that grade")
|
||||
|
||||
|
||||
class MatchOutput(BaseModel):
|
||||
"""Output wrapper for match items"""
|
||||
items: List[MatchItem] = Field(description="List of match items generated from source text")
|
||||
|
||||
items: List[MatchItem] = Field(
|
||||
description="List of match items generated from source text"
|
||||
)
|
||||
metadata: MatchMetadata = Field(description="Metadata about the content")
|
||||
|
||||
|
||||
# Output parser
|
||||
@@ -26,56 +60,110 @@ output_parser = PydanticOutputParser(pydantic_object=MatchOutput)
|
||||
|
||||
# ============== CONFIG ==============
|
||||
GAME_CONFIG = {
|
||||
# === REQUIRED ===
|
||||
"game_type": "match",
|
||||
"type_id": 3,
|
||||
"display_name": "Match with Image",
|
||||
"description": "Match sentences with images",
|
||||
|
||||
"active": True,
|
||||
|
||||
"min_items": 2,
|
||||
"max_items": 10,
|
||||
"description": "Match words or phrases with their corresponding images",
|
||||
"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""",
|
||||
# === OPTIONAL ===
|
||||
"active": True,
|
||||
"max_items": 10,
|
||||
# Input validation rules
|
||||
"input_format_rules": [
|
||||
"Text MUST be a list of words or phrases separated by commas, semicolons, or newlines",
|
||||
"NOT suitable for long sentences or paragraphs",
|
||||
"Each item should be a concrete noun/concept that can be visualized",
|
||||
],
|
||||
# Analyzer rules - khi nào nên chọn game này
|
||||
"analyzer_rules": [
|
||||
"Text is a list of words or short phrases",
|
||||
"Words represent concrete objects/concepts that can be visualized",
|
||||
"Examples: 'apple, banana, orange' or 'cat; dog; bird'",
|
||||
"NOT suitable for abstract concepts or long sentences",
|
||||
],
|
||||
# Generation rules - cách tạo nội dung
|
||||
"generation_rules": [
|
||||
"KEEP ORIGINAL LANGUAGE for 'word' field - Do NOT translate",
|
||||
"original_quote = EXACT copy from source before cleaning",
|
||||
"Clean numbering like '1.', 'a)', '•' from word field",
|
||||
"Each word/phrase should represent a visualizable concept",
|
||||
# Image rules
|
||||
"image_description: MUST be DETAILED visual description in ENGLISH",
|
||||
"image_description: Describe colors, shapes, actions, context",
|
||||
"image_keywords: 2-3 English keywords for search",
|
||||
"image_is_complex: TRUE for humans, precise counts, complex scenes",
|
||||
"NEVER leave image_description empty!",
|
||||
# Quality rules
|
||||
"Each image should be visually DISTINCT from others",
|
||||
"Avoid generic descriptions - be specific",
|
||||
],
|
||||
"examples": [], # Defined below
|
||||
}
|
||||
|
||||
|
||||
# ============== EXAMPLES ==============
|
||||
EXAMPLES = [
|
||||
{
|
||||
"input": "The Sun is a star. The Moon orbits Earth.",
|
||||
"input": "apple; banana;",
|
||||
"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": "apple",
|
||||
"original_quote": "apple",
|
||||
"image_description": "A shiny red apple with a green leaf on top",
|
||||
"image_keywords": ["apple", "fruit", "red"],
|
||||
"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
|
||||
}
|
||||
]
|
||||
"word": "banana",
|
||||
"original_quote": "banana",
|
||||
"image_description": "A curved yellow banana",
|
||||
"image_keywords": ["banana", "fruit", "yellow"],
|
||||
"image_is_complex": False,
|
||||
},
|
||||
],
|
||||
"metadata": {
|
||||
"title": "Fruits",
|
||||
"description": "Common fruits vocabulary",
|
||||
"grade": 1,
|
||||
"type": "match",
|
||||
"difficulty": 1,
|
||||
},
|
||||
},
|
||||
"why_suitable": "Has distinct concepts that can be visualized and matched"
|
||||
}
|
||||
"why_suitable": "Simple words representing concrete objects that can be visualized",
|
||||
},
|
||||
{
|
||||
"input": "1. elephant\n2. giraffe\n",
|
||||
"output": {
|
||||
"items": [
|
||||
{
|
||||
"word": "elephant",
|
||||
"original_quote": "1. elephant",
|
||||
"image_description": "A large grey elephant with big ears and long trunk",
|
||||
"image_keywords": ["elephant", "animal", "africa"],
|
||||
"image_is_complex": False,
|
||||
},
|
||||
{
|
||||
"word": "giraffe",
|
||||
"original_quote": "2. giraffe",
|
||||
"image_description": "A tall giraffe with brown spots and long neck",
|
||||
"image_keywords": ["giraffe", "tall", "spots"],
|
||||
"image_is_complex": False,
|
||||
},
|
||||
],
|
||||
"metadata": {
|
||||
"title": "African Animals",
|
||||
"description": "Safari animals vocabulary",
|
||||
"grade": 2,
|
||||
"type": "match",
|
||||
"difficulty": 1,
|
||||
},
|
||||
},
|
||||
"why_suitable": "Numbered list of animals - numbering will be cleaned",
|
||||
},
|
||||
]
|
||||
|
||||
GAME_CONFIG["examples"] = EXAMPLES
|
||||
|
||||
Reference in New Issue
Block a user