Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

update prompt

黄伟韬d9dacb630541
diff --git a/metagpt/strategy/experience_retriever.py b/metagpt/strategy/experience_retriever.py
index d5601a6a1..5cb0573b2 100644
--- a/metagpt/strategy/experience_retriever.py
+++ b/metagpt/strategy/experience_retriever.py
@@ -1027,9 +1027,9 @@ Thought: Now that the changes have been pushed to the remote repository, due to
]
```
-## example 11
-The requirements is a product website contain some goods including cap, dress and tshit.
-I think the website should conatin the picture of the goods,but user did not provide, so i will get the image first.
+## example 12
+The requirement is to create a product website featuring goods such as caps, dresses, and T-shirts.
+I believe pictures would improve the site, so I will get the images first.
```json
[
{
diff --git a/metagpt/tools/libs/image_getter.py b/metagpt/tools/libs/image_getter.py
index bda939ea9..1420f9d7f 100644
--- a/metagpt/tools/libs/image_getter.py
+++ b/metagpt/tools/libs/image_getter.py
@@ -39,25 +39,25 @@ class ImageGetter(BaseModel):
browser_ctx = self.browser_ctx = await browser.new_context()
self.page = await browser_ctx.new_page()
- async def get_image(self, search_term, save_file_path):
+ async def get_image(self, search_term, image_save_path):
"""
Get an image related to the search term.
Args:
search_term (str): The term to search for the image.
- save_file_path (str): The file path where the image will
+ image_save_path (str): The file path where the image will be saved.
"""
- # Seach image
+ # Search for images from https://unsplash.com/s/photos/
url = f"https://unsplash.com/s/photos/{search_term}/"
if self.page is None:
await self.start()
await self.page.goto(url, wait_until="domcontentloaded")
- # Wait for the element
+ # Wait until the image element is loaded
try:
await self.page.wait_for_selector(".zNNw1 > div > img:nth-of-type(2)")
except TimeoutError:
return f"{search_term} not found. Please broaden the search term."
-
+ # Get the base64 code of the first retrieved image
image_base64 = await self.page.evaluate(
"""async () => {
var img = document.querySelector('.zNNw1 > div > img:nth-of-type(2)');
@@ -76,12 +76,13 @@ class ImageGetter(BaseModel):
}"""
)
if image_base64:
- file_path = Path(save_file_path)
+ # Save image
+ file_path = Path(image_save_path)
os.makedirs(file_path.parent, exist_ok=True)
- with open(save_file_path, "wb") as f:
+ with open(image_save_path, "wb") as f:
imgstr = re.sub("data:image/.*?;base64,", "", image_base64)
image_data = base64.b64decode(imgstr)
f.write(image_data)
- return f"{search_term} found. The image is saved in {save_file_path}."
+ return f"{search_term} found. The image is saved in {image_save_path}."
else:
return f"{search_term} not found. Please broaden the search term."