experiment pool init

This commit is contained in:
seehi 2024-06-04 10:28:39 +08:00
parent 46aa6f1975
commit 471310f3b3
14 changed files with 258 additions and 55 deletions

View file

@ -0,0 +1,26 @@
"""Decorator example of experience pool."""
import asyncio
import uuid
from metagpt.exp_pool import exp_cache, exp_manager
from metagpt.logs import logger
@exp_cache
async def produce(req):
return f"{req} {uuid.uuid4().hex}"
async def main():
req = "Water"
resp = await produce(req)
logger.info(f"The resp of `produce{req}` is: {resp}")
exps = await exp_manager.query_exps(req)
logger.info(f"Find experiences: {exps}")
if __name__ == "__main__":
asyncio.run(main())

View file

@ -1,21 +0,0 @@
from metagpt.exp_pool.manager import ExperiencePoolManager
from metagpt.exp_pool.schema import Experience
from pprint import pprint
import asyncio
# import logging
# logging.basicConfig(level=logging.DEBUG)
async def main():
req = "2048 game"
exp = Experience(req=req, resp="python code")
manager = ExperiencePoolManager()
# pprint(manager.storage.get())
# manager.create_exp(exp)
result = await manager.query_exp(req)
print(result)
if __name__ == "__main__":
asyncio.run(main())

View file

@ -0,0 +1,29 @@
"""Simple example of experience pool."""
import asyncio
from metagpt.exp_pool import exp_manager
from metagpt.exp_pool.schema import EntryType, Experience
from metagpt.logs import logger
async def main():
req = "Simple task."
# 1. Find experiences.
exps = await exp_manager.query_exps(req)
if exps:
logger.info(f"Experiences already exist for the request `{req}`: {exps}")
return
# 2. Create a new experience if none exist
exp_manager.create_exp(Experience(req=req, resp="Simple echo.", entry_type=EntryType.MANUAL))
logger.info(f"New experience created for the request `{req}`.")
# 3. Find again
exps = await exp_manager.query_exps(req)
logger.info(f"Updated experiences: {exps}")
if __name__ == "__main__":
asyncio.run(main())