Allow disabling images by config

This commit is contained in:
Carlos Bazaga
2025-09-05 22:51:02 +02:00
parent 9c301f8bee
commit 97967e33e9
3 changed files with 21 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ class Gameplay_Config(NamedTuple):
scene_style: str
scene_prompt: str
storyteller_prompt: str
disable_img: str
error_img: str
error_narrator: str
error_illustrator: str
@@ -36,18 +37,23 @@ def get_gameplay_function(config: Gameplay_Config):
history.append({"role": "user", "content": message})
history.append({"role": "assistant", "content": response.model_dump_json()})
# Draw scene.
_logger.info(f'DRAWING SCENE...')
try:
scene_data = {'scene_description': response.scene_description,
'scene_style': config.scene_style}
scene_prompt = config.scene_prompt.format(**scene_data)
_logger.info(f'PROMPT BODY IS: \n\n{scene_prompt}\n')
_logger.info(f'PROMPT LENGTH IS: {len(scene_prompt)}')
scene = config.draw_func(scene_prompt)
except Exception as ex:
scene = config.error_img
response = config.error_illustrator.format(ex=ex)
_logger.warning(f'ERROR DRAWING SCENE: {ex}')
if config.draw_func:
_logger.info(f'DRAWING SCENE...')
try:
scene_data = {'scene_description': response.scene_description,
'scene_style': config.scene_style}
scene_prompt = config.scene_prompt.format(**scene_data)
_logger.info(f'PROMPT BODY IS: \n\n{scene_prompt}\n')
_logger.info(f'PROMPT LENGTH IS: {len(scene_prompt)}')
scene = config.draw_func(scene_prompt)
except Exception as ex:
scene = config.error_img
response = config.error_illustrator.format(ex=ex)
_logger.warning(f'ERROR DRAWING SCENE: {ex}')
return scene, response, history, ''
else:
_logger.info(f'DRAWING DISABLED...')
scene = config.disable_img
return scene, response, history, ''
return gameplay_function