diff --git a/metagpt/actions/skill_action.py b/metagpt/actions/skill_action.py index 301cebaab..5af2b3fc4 100644 --- a/metagpt/actions/skill_action.py +++ b/metagpt/actions/skill_action.py @@ -29,9 +29,7 @@ class ArgumentsParingAction(Action): @property def prompt(self): - prompt = "You are a function parser. You can convert spoken words into function parameters.\n" - prompt += "\n---\n" - prompt += f"{self.skill.name} function parameters description:\n" + prompt = f"{self.skill.name} function parameters description:\n" for k, v in self.skill.arguments.items(): prompt += f"parameter `{k}`: {v}\n" prompt += "\n---\n" @@ -49,7 +47,10 @@ class ArgumentsParingAction(Action): async def run(self, with_message=None, **kwargs) -> Message: prompt = self.prompt - rsp = await self.llm.aask(msg=prompt, system_msgs=[]) + rsp = await self.llm.aask( + msg=prompt, + system_msgs=["You are a function parser. You can convert spoken words into function parameters."], + ) logger.debug(f"SKILL:{prompt}\n, RESULT:{rsp}") self.args = ArgumentsParingAction.parse_arguments(skill_name=self.skill.name, txt=rsp) self.rsp = Message(content=rsp, role="assistant", instruct_content=self.args, cause_by=self) diff --git a/metagpt/memory/brain_memory.py b/metagpt/memory/brain_memory.py index ff29eaddb..384c4d3a9 100644 --- a/metagpt/memory/brain_memory.py +++ b/metagpt/memory/brain_memory.py @@ -201,11 +201,14 @@ class BrainMemory(BaseModel): @staticmethod async def _openai_is_related(text1, text2, llm, **kwargs): - 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." + context = f"## Paragraph 1\n{text2}\n---\n## Paragraph 2\n{text1}\n" + rsp = await llm.aask( + msg=context, + system_msgs=[ + "You are a tool capable of determining whether two paragraphs are semantically related." + 'Return "TRUE" if "Paragraph 1" is semantically relevant to "Paragraph 2", otherwise return "FALSE".' + ], ) - rsp = await llm.aask(msg=command, system_msgs=[]) result = True if "TRUE" in rsp else False p2 = text2.replace("\n", "") p1 = text1.replace("\n", "") @@ -223,12 +226,16 @@ class BrainMemory(BaseModel): @staticmethod async def _openai_rewrite(sentence: str, context: str, llm): - command = ( - f"{context}\n\nExtract relevant information from every preceding sentence and use it to succinctly " - f"supplement or rewrite the following text in brief and clear:\n{sentence}" + prompt = f"## Context\n{context}\n---\n## Sentence\n{sentence}\n" + rsp = await llm.aask( + msg=prompt, + system_msgs=[ + 'You are a tool augmenting the "Sentence" with information from the "Context".', + "Do not supplement the context with information that is not present, especially regarding the subject and object.", + "Return the augmented sentence.", + ], ) - rsp = await llm.aask(msg=command, system_msgs=[]) - logger.info(f"REWRITE:\nCommand: {command}\nRESULT: {rsp}\n") + logger.info(f"REWRITE:\nCommand: {prompt}\nRESULT: {rsp}\n") return rsp @staticmethod @@ -293,14 +300,14 @@ class BrainMemory(BaseModel): """Generate text summary""" if len(text) < max_words: return text + system_msgs = [ + "You are a tool for summarizing and abstracting text.", + "Return the summarized text to less than 200 words.", + ] if keep_language: - command = f".Translate the above content into a summary of less than {max_words} words in language of the content strictly." - else: - command = f"Translate the above content into a summary of less than {max_words} words." - msg = text + "\n\n" + command - logger.debug(f"summary ask:{msg}") - response = await self.llm.aask(msg=msg, system_msgs=[]) - logger.debug(f"summary rsp: {response}") + system_msgs.append("The generated summary should be in the same language as the original text.") + response = await self.llm.aask(msg=text, system_msgs=system_msgs) + logger.debug(f"{text}\nsummary rsp: {response}") return response @staticmethod diff --git a/setup.py b/setup.py index 2b16e2cd1..235c18f53 100644 --- a/setup.py +++ b/setup.py @@ -57,7 +57,7 @@ extras_require["dev"] = (["pylint~=3.0.3", "black~=23.3.0", "isort~=5.12.0", "pr setup( name="metagpt", - version="0.6.7", + version="0.6.8", description="The Multi-Agent Framework", long_description=long_description, long_description_content_type="text/markdown",