decorator.py
1 """ 2 This script demonstrates how to automatically store experiences using @exp_cache and query the stored experiences. 3 """ 4 5 import asyncio 6 import uuid 7 8 from metagpt.exp_pool import exp_cache, get_exp_manager 9 from metagpt.logs import logger 10 11 12 @exp_cache() 13 async def produce(req=""): 14 return f"{req} {uuid.uuid4().hex}" 15 16 17 async def main(): 18 req = "Water" 19 20 resp = await produce(req=req) 21 logger.info(f"The response of `produce({req})` is: {resp}") 22 23 exps = await get_exp_manager().query_exps(req) 24 logger.info(f"Find experiences: {exps}") 25 26 27 if __name__ == "__main__": 28 asyncio.run(main())