Skip to content

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

refactor: think

莘权 马03019a304bfd
diff --git a/metagpt/actions/talk_action.py b/metagpt/actions/talk_action.py
index 81caef013..4afed8014 100644
--- a/metagpt/actions/talk_action.py
+++ b/metagpt/actions/talk_action.py
@@ -44,6 +44,7 @@ class TalkAction(Action):
f"Answer the following questions strictly in {language}, and the answers must follow the Markdown format.\n "
f"{self._talk}"
)
+ logger.info(f"PROMPT: {prompt}")
return prompt
@property
diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.py
index bf2ca7f14..d84109f6a 100644
--- a/metagpt/provider/openai_api.py
+++ b/metagpt/provider/openai_api.py
@@ -276,16 +276,22 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
return response
async def is_related(self, text1, text2):
- command = f"{text1}\n{text2}\n\nIf the two sentences above are related, return [TRUE] brief and clear. Otherwise, return [FALSE]."
+ # command = f"{text1}\n{text2}\n\nIf the two sentences above are related, return [TRUE] brief and clear. Otherwise, return [FALSE]."
+ command = f"{text2}\n\nIs there any sentence above related to the following sentence: {text1}.\nIf is there any relevance, return [TRUE] brief and clear. Otherwise, return [FALSE] brief and clear."
rsp = await self.aask(msg=command, system_msgs=[])
- result, _ = self.extract_info(rsp)
- return result == "TRUE"
+ result = True if "TRUE" in rsp else False
+ p2 = text2.replace("\n", "")
+ p1 = text1.replace("\n", "")
+ logger.info(f"IS_RELATED:\nParagraph 1: {p2}\nParagraph 2: {p1}\nRESULT: {result}")
+ return result
async def rewrite(self, sentence: str, context: str):
- command = (
- f"{context}\n\nConsidering the content above, rewrite and return this sentence brief and clear:\n{sentence}"
- )
+ # command = (
+ # f"{context}\n\nConsidering the content above, rewrite and return this sentence brief and clear:\n{sentence}"
+ # )
+ command = f"{context}\n\nExtract relevant information from every preceding sentence and use it to succinctly supplement or rewrite the following text in brief and clear:\n{sentence}"
rsp = await self.aask(msg=command, system_msgs=[])
+ logger.info(f"REWRITE:\nCommand: {command}\nRESULT: {rsp}")
return rsp
@staticmethod
@@ -316,8 +322,7 @@ class OpenAIGPTAPI(BaseGPTAPI, RateLimiter):
return windows
@staticmethod
- def extract_info(input_string):
- pattern = r"\[([A-Z]+)\]:\s*(.+)"
+ def extract_info(input_string, pattern=r"\[([A-Z]+)\]:\s*(.+)"):
match = re.match(pattern, input_string)
if match:
return match.group(1), match.group(2)
diff --git a/metagpt/roles/assistant.py b/metagpt/roles/assistant.py
index 87127cbab..ac80a4bc8 100644
--- a/metagpt/roles/assistant.py
+++ b/metagpt/roles/assistant.py
@@ -54,18 +54,15 @@ class Assistant(Role):
last_talk = await self.refine_memory()
if not last_talk:
return False
- prompt = f"Refer to this sentence:\n {last_talk}\n"
+ prompt = ""
skills = self.skills.get_skill_list()
for desc, name in skills.items():
- prompt += (
- f"If want you to do {desc}, return `[SKILL]: {name}` brief and clear. For instance: [SKILL]: {name}\n"
- )
- prompt += "If the preceding text presents a complete question and solution, rewrite and return `[SOLUTION]: {problem}` brief and clear. For instance: [SOLUTION]: Solution for distributing watermelon\n"
- prompt += "If the preceding text presents an unresolved issue and its corresponding discussion, rewrite and return `[PROBLEM]: {problem}` brief and clear. For instance: [PROBLEM]: How to distribute watermelon?\n"
- prompt += "Otherwise, rewrite and return `[TALK]: {talk}` brief and clear. For instance: [TALK]: distribute watermelon"
+ prompt += f"If the text explicitly want you to {desc}, return `[SKILL]: {name}` brief and clear. For instance: [SKILL]: {name}\n"
+ prompt += 'Otherwise, return `[TALK]: {talk}` brief and clear. For instance: if {talk} is "xxxx" return [TALK]: xxxx\n\n'
+ prompt += f"Now what specific action is explicitly mentioned in the text: {last_talk}\n"
logger.info(prompt)
rsp = await self._llm.aask(prompt, [])
- logger.info(rsp)
+ logger.info(f"THINK: {prompt}\n, THINK RESULT: {rsp}\n")
return await self._plan(rsp, last_talk=last_talk)
async def act(self) -> ActionOutput:
@@ -90,7 +87,6 @@ class Assistant(Role):
skill, text = Assistant.extract_info(input_string=rsp)
handlers = {
MessageType.Talk.value: self.talk_handler,
- MessageType.Problem.value: self.talk_handler,
MessageType.Skill.value: self.skill_handler,
}
handler = handlers.get(skill, self.talk_handler)