diff --git a/examples/dalle_gpt4v_agent.py b/examples/dalle_gpt4v_agent.py index 3974f5d9b..2b54b18a0 100644 --- a/examples/dalle_gpt4v_agent.py +++ b/examples/dalle_gpt4v_agent.py @@ -16,11 +16,11 @@ import asyncio from PIL import Image -from metagpt.roles.role import Role from metagpt.actions.action import Action -from metagpt.utils.common import encode_image -from metagpt.schema import Message from metagpt.logs import logger +from metagpt.roles.role import Role +from metagpt.schema import Message +from metagpt.utils.common import encode_image class GenAndImproveImageAction(Action): @@ -31,15 +31,19 @@ class GenAndImproveImageAction(Action): return imgs[0] async def refine_prompt(self, old_prompt: str, image: Image) -> str: - msg = f"You are a creative painter, with the given generated image and old prompt: {old_prompt}, " \ - f"please refine the prompt and generate new one. Just output the new prompt." + msg = ( + f"You are a creative painter, with the given generated image and old prompt: {old_prompt}, " + f"please refine the prompt and generate new one. Just output the new prompt." + ) b64_img = encode_image(image) new_prompt = await self.llm.aask(msg=msg, images=[b64_img]) return new_prompt async def evaluate_images(self, old_prompt: str, images: list[Image]) -> str: - msg = "With the prompt and two generated image, to judge if the second one is better than the first one. " \ - "If so, just output True else output False" + msg = ( + "With the prompt and two generated image, to judge if the second one is better than the first one. " + "If so, just output True else output False" + ) b64_imgs = [encode_image(img) for img in images] res = await self.llm.aask(msg=msg, images=b64_imgs) return res @@ -76,5 +80,6 @@ async def main(): role = Painter() await role.run(with_message="a girl with flowers") + if __name__ == "__main__": asyncio.run(main())