Merge branch 'main' into feat_basemodel

This commit is contained in:
better629 2023-12-22 22:33:06 +08:00 committed by GitHub
commit 19d33110bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 453 additions and 114 deletions

View file

@ -64,7 +64,7 @@ class AgentCreator(Role):
self._init_actions([CreateAgent])
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")
logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo
msg = self._rc.memory.get()[-1]

View file

@ -60,7 +60,7 @@ class SimpleCoder(Role):
self._init_actions([SimpleWriteCode])
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")
logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo # todo will be SimpleWriteCode()
msg = self.get_memories(k=1)[0] # find the most recent messages
@ -80,7 +80,7 @@ class RunnableCoder(Role):
self._set_react_mode(react_mode=RoleReactMode.BY_ORDER.value)
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")
logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
# By choosing the Action by order under the hood
# todo will be first SimpleWriteCode() then SimpleRunCode()
todo = self._rc.todo

View file

@ -80,7 +80,7 @@ class SimpleTester(Role):
self._watch([SimpleWriteCode, SimpleWriteReview]) # feel free to try this too
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")
logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo
# context = self.get_memories(k=1)[0].content # use the most recent memory as context

View file

@ -63,7 +63,7 @@ class Debator(Role):
return len(self._rc.news)
async def _act(self) -> Message:
logger.info(f"{self._setting}: ready to {self._rc.todo}")
logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo # An instance of SpeakAloud
memories = self.get_memories()

22
examples/debate_simple.py Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time : 2023/12/22
@Author : alexanderwu
@File : debate_simple.py
"""
import asyncio
from metagpt.actions import Action, UserRequirement
from metagpt.environment import Environment
from metagpt.roles import Role
from metagpt.team import Team
action1 = Action(name="BidenSay", instruction="发表政见,充满激情的反驳特朗普最新消息,尽最大努力获得选票")
action2 = Action(name="TrumpSay", instruction="发表政见充满激情的反驳拜登最新消息尽最大努力获得选票MAGA")
biden = Role(name="拜登", profile="民主党候选人", goal="大选获胜", actions=[action1], watch=[action2, UserRequirement])
trump = Role(name="特朗普", profile="共和党候选人", goal="大选获胜", actions=[action2], watch=[action1])
env = Environment(desc="US election live broadcast")
team = Team(investment=10.0, env=env, roles=[biden, trump])
asyncio.run(team.run(idea="主题:气候变化,用中文辩论", n_round=5))

View file

@ -5,12 +5,13 @@
"""
import asyncio
from metagpt.actions import Action
from langchain.embeddings import OpenAIEmbeddings
from metagpt.config import CONFIG
from metagpt.const import DATA_PATH
from metagpt.document_store import FaissStore
from metagpt.logs import logger
from metagpt.roles import Sales
from metagpt.schema import Message
""" example.json, e.g.
[
@ -26,14 +27,15 @@ from metagpt.schema import Message
"""
def get_store():
embedding = OpenAIEmbeddings(openai_api_key=CONFIG.openai_api_key, openai_api_base=CONFIG.openai_base_url)
return FaissStore(DATA_PATH / "example.json", embedding=embedding)
async def search():
store = FaissStore(DATA_PATH / "example.json")
role = Sales(profile="Sales", store=store)
role._watch({Action})
queries = [
Message(content="Which facial cleanser is good for oily skin?", cause_by=Action),
Message(content="Is L'Oreal good to use?", cause_by=Action),
]
role = Sales(profile="Sales", store=get_store())
queries = ["Which facial cleanser is good for oily skin?", "Is L'Oreal good to use?"]
for query in queries:
logger.info(f"User: {query}")
result = await role.run(query)