diff --git a/community-contributions/dungeon_extraction_game/game/config.py b/community-contributions/dungeon_extraction_game/game/config.py index ae6a70f..945d987 100644 --- a/community-contributions/dungeon_extraction_game/game/config.py +++ b/community-contributions/dungeon_extraction_game/game/config.py @@ -8,7 +8,7 @@ from .gameplay import Gameplay_Config from .illustrator import draw_dalle_2, draw_dalle_3, draw_gemini, draw_gpt, draw_grok from .illustrator import draw_grok_x from .interface import Interface_Config -from .storyteller import narrate +from .storyteller import narrate, set_description_limit # Environment initialization. @@ -65,6 +65,7 @@ SCENE_STYLE = 'Photorealistic' # Set a Storyteller scene descriptions size limit to keep the draw prompt in range. STORYTELLER_LIMIT = 730 +set_description_limit(STORYTELLER_LIMIT) # Need to patch pydantic class model. # Define the storyteller behaviour. Remember to specify a limited scene length. STORYTELLER_PROMPT = f""" diff --git a/community-contributions/dungeon_extraction_game/game/storyteller/__init__.py b/community-contributions/dungeon_extraction_game/game/storyteller/__init__.py index 042ceea..92d6739 100644 --- a/community-contributions/dungeon_extraction_game/game/storyteller/__init__.py +++ b/community-contributions/dungeon_extraction_game/game/storyteller/__init__.py @@ -1,6 +1,6 @@ """AI Mastered Dungeon Extraction Game Storyteller package.""" -from .storyteller import narrate +from .storyteller import narrate, set_description_limit -__all__ = ['narrate'] +__all__ = ['narrate', 'set_description_limit'] diff --git a/community-contributions/dungeon_extraction_game/game/storyteller/storyteller.py b/community-contributions/dungeon_extraction_game/game/storyteller/storyteller.py index bc976f2..4cae135 100644 --- a/community-contributions/dungeon_extraction_game/game/storyteller/storyteller.py +++ b/community-contributions/dungeon_extraction_game/game/storyteller/storyteller.py @@ -2,11 +2,11 @@ from typing import List +from annotated_types import MaxLen from dotenv import load_dotenv from openai import OpenAI from pydantic import BaseModel, Field -from ..config import STORYTELLER_LIMIT from .tools import handle_tool_call, tools @@ -30,7 +30,7 @@ class _character_sheet(BaseModel): class _response_format(BaseModel): game_over: bool - scene_description: str = Field(..., max_length=STORYTELLER_LIMIT) + scene_description: str = Field(..., max_length=700) dungeon_deepness: int adventure_time: int adventurer_status: _character_sheet @@ -48,6 +48,11 @@ class _response_format(BaseModel): return response_view +def set_description_limit(limit): # HBD: We modify the class definition in runtime. + """Update "_response_format" class to set a new "scene_description" max length.""" + _response_format.model_fields['scene_description'].metadata[0] = MaxLen(limit) + + # Function definition. def narrate(message, history, system_message, client=CLIENT, model=MODEL): """Chat with the game engine."""