check point
This commit is contained in:
81
backup_source/match.py
Normal file
81
backup_source/match.py
Normal 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"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user