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:
@@ -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_dalle_2, draw_dalle_3, draw_gemini, draw_gpt, draw_grok
|
||||||
from .illustrator import draw_grok_x
|
from .illustrator import draw_grok_x
|
||||||
from .interface import Interface_Config
|
from .interface import Interface_Config
|
||||||
from .storyteller import narrate
|
from .storyteller import narrate, set_description_limit
|
||||||
|
|
||||||
|
|
||||||
# Environment initialization.
|
# Environment initialization.
|
||||||
@@ -65,6 +65,7 @@ SCENE_STYLE = 'Photorealistic'
|
|||||||
|
|
||||||
# Set a Storyteller scene descriptions size limit to keep the draw prompt in range.
|
# Set a Storyteller scene descriptions size limit to keep the draw prompt in range.
|
||||||
STORYTELLER_LIMIT = 730
|
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.
|
# Define the storyteller behaviour. Remember to specify a limited scene length.
|
||||||
STORYTELLER_PROMPT = f"""
|
STORYTELLER_PROMPT = f"""
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"""AI Mastered Dungeon Extraction Game Storyteller package."""
|
"""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']
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
from annotated_types import MaxLen
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from ..config import STORYTELLER_LIMIT
|
|
||||||
from .tools import handle_tool_call, tools
|
from .tools import handle_tool_call, tools
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ class _character_sheet(BaseModel):
|
|||||||
|
|
||||||
class _response_format(BaseModel):
|
class _response_format(BaseModel):
|
||||||
game_over: bool
|
game_over: bool
|
||||||
scene_description: str = Field(..., max_length=STORYTELLER_LIMIT)
|
scene_description: str = Field(..., max_length=700)
|
||||||
dungeon_deepness: int
|
dungeon_deepness: int
|
||||||
adventure_time: int
|
adventure_time: int
|
||||||
adventurer_status: _character_sheet
|
adventurer_status: _character_sheet
|
||||||
@@ -48,6 +48,11 @@ class _response_format(BaseModel):
|
|||||||
return response_view
|
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.
|
# Function definition.
|
||||||
def narrate(message, history, system_message, client=CLIENT, model=MODEL):
|
def narrate(message, history, system_message, client=CLIENT, model=MODEL):
|
||||||
"""Chat with the game engine."""
|
"""Chat with the game engine."""
|
||||||
|
|||||||
Reference in New Issue
Block a user