mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-02 14:45:17 +02:00
experiment pool init
This commit is contained in:
parent
46aa6f1975
commit
471310f3b3
14 changed files with 258 additions and 55 deletions
26
examples/exp_pool/decorator.py
Normal file
26
examples/exp_pool/decorator.py
Normal 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())
|
||||
|
|
@ -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())
|
||||
29
examples/exp_pool/simple.py
Normal file
29
examples/exp_pool/simple.py
Normal 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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue