Fixed circular import issue.

The Pydantic class will be updated on runtime before using it on calls.

The field now defaults to 700 which is a safe size.
This commit is contained in:
Carlos Bazaga
2025-09-05 20:32:37 +02:00
parent 67f3307aff
commit 369a2d3f2d
3 changed files with 11 additions and 5 deletions

View File

@@ -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']

View File

@@ -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."""