Allow disabling images by config
This commit is contained in:
@@ -15,7 +15,8 @@ from .storyteller import narrate, set_description_limit
|
|||||||
load_dotenv(override=True)
|
load_dotenv(override=True)
|
||||||
|
|
||||||
|
|
||||||
# Choose draw function. (Choose one from the imported ones up there)
|
# Choose draw function.
|
||||||
|
# Choose one from the imported ones up there or set to None to disable images.
|
||||||
DRAW_FUNCTION = draw_dalle_2
|
DRAW_FUNCTION = draw_dalle_2
|
||||||
|
|
||||||
# Define a sample scene description for testing purposes.
|
# Define a sample scene description for testing purposes.
|
||||||
@@ -160,6 +161,7 @@ GAME_CONFIG = Gameplay_Config(
|
|||||||
scene_style=SCENE_STYLE,
|
scene_style=SCENE_STYLE,
|
||||||
scene_prompt=SCENE_PROMPT,
|
scene_prompt=SCENE_PROMPT,
|
||||||
storyteller_prompt=STORYTELLER_PROMPT,
|
storyteller_prompt=STORYTELLER_PROMPT,
|
||||||
|
disable_img='images/disabled.jpg',
|
||||||
error_img='images/machine.jpg',
|
error_img='images/machine.jpg',
|
||||||
error_narrator='NEURAL SINAPSIS ERROR\n\n{ex}\n\nEND OF LINE\n\nRE-SUBMIT_',
|
error_narrator='NEURAL SINAPSIS ERROR\n\n{ex}\n\nEND OF LINE\n\nRE-SUBMIT_',
|
||||||
error_illustrator='NEURAL PROJECTION ERROR\n\n{ex}\n\nEND OF LINE\n\nRE-SUBMIT_',)
|
error_illustrator='NEURAL PROJECTION ERROR\n\n{ex}\n\nEND OF LINE\n\nRE-SUBMIT_',)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ class Gameplay_Config(NamedTuple):
|
|||||||
scene_style: str
|
scene_style: str
|
||||||
scene_prompt: str
|
scene_prompt: str
|
||||||
storyteller_prompt: str
|
storyteller_prompt: str
|
||||||
|
disable_img: str
|
||||||
error_img: str
|
error_img: str
|
||||||
error_narrator: str
|
error_narrator: str
|
||||||
error_illustrator: str
|
error_illustrator: str
|
||||||
@@ -36,18 +37,23 @@ def get_gameplay_function(config: Gameplay_Config):
|
|||||||
history.append({"role": "user", "content": message})
|
history.append({"role": "user", "content": message})
|
||||||
history.append({"role": "assistant", "content": response.model_dump_json()})
|
history.append({"role": "assistant", "content": response.model_dump_json()})
|
||||||
# Draw scene.
|
# Draw scene.
|
||||||
_logger.info(f'DRAWING SCENE...')
|
if config.draw_func:
|
||||||
try:
|
_logger.info(f'DRAWING SCENE...')
|
||||||
scene_data = {'scene_description': response.scene_description,
|
try:
|
||||||
'scene_style': config.scene_style}
|
scene_data = {'scene_description': response.scene_description,
|
||||||
scene_prompt = config.scene_prompt.format(**scene_data)
|
'scene_style': config.scene_style}
|
||||||
_logger.info(f'PROMPT BODY IS: \n\n{scene_prompt}\n')
|
scene_prompt = config.scene_prompt.format(**scene_data)
|
||||||
_logger.info(f'PROMPT LENGTH IS: {len(scene_prompt)}')
|
_logger.info(f'PROMPT BODY IS: \n\n{scene_prompt}\n')
|
||||||
scene = config.draw_func(scene_prompt)
|
_logger.info(f'PROMPT LENGTH IS: {len(scene_prompt)}')
|
||||||
except Exception as ex:
|
scene = config.draw_func(scene_prompt)
|
||||||
scene = config.error_img
|
except Exception as ex:
|
||||||
response = config.error_illustrator.format(ex=ex)
|
scene = config.error_img
|
||||||
_logger.warning(f'ERROR DRAWING SCENE: {ex}')
|
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 scene, response, history, ''
|
||||||
return gameplay_function
|
return gameplay_function
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 892 KiB |
Reference in New Issue
Block a user