From 8239a110dc8acd06bdb2ec87f6338a684c8d21d4 Mon Sep 17 00:00:00 2001 From: MoyiTech Date: Wed, 6 Mar 2024 00:44:19 +0800 Subject: [PATCH 1/7] feat: fix JSONDecodeError error caused by incorrect indentation used in repair_llm.output in config2.example.yaml --- config/config2.example.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/config2.example.yaml b/config/config2.example.yaml index a17d174b3..3a5cc3585 100644 --- a/config/config2.example.yaml +++ b/config/config2.example.yaml @@ -3,7 +3,6 @@ llm: base_url: "YOUR_BASE_URL" api_key: "YOUR_API_KEY" model: "gpt-4-turbo-preview" # or gpt-3.5-turbo-1106 / gpt-4-1106-preview - repair_llm_output: true # when the output is not a valid json, try to repair it proxy: "YOUR_PROXY" # for LLM API requests pricing_plan: "" # Optional. If invalid, it will be automatically filled in with the value of the `model`. # Azure-exclusive pricing plan mappings: @@ -13,6 +12,8 @@ llm: # - gpt-4 8k: "gpt-4" # See for more: https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/ +repair_llm_output: true # when the output is not a valid json, try to repair it + proxy: "YOUR_PROXY" # for tools like requests, playwright, selenium, etc. search: From a7eaf6666c43b42d26cf20fd7e09cc62602e7f50 Mon Sep 17 00:00:00 2001 From: Abhishek0075 Date: Tue, 5 Mar 2024 23:33:10 +0530 Subject: [PATCH 2/7] change in two examples file --- examples/debate.py | 2 +- examples/search_with_specific_engine.py | 31 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/examples/debate.py b/examples/debate.py index 72ab8796d..22cfbf39e 100644 --- a/examples/debate.py +++ b/examples/debate.py @@ -105,4 +105,4 @@ def main(idea: str, investment: float = 3.0, n_round: int = 10): if __name__ == "__main__": - fire.Fire(main) + fire.Fire(main) # run as python debate.py --idea="TOPIC" --investment=3.0 --n_round=5 diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.py index 97b1378ee..c9fa0395e 100644 --- a/examples/search_with_specific_engine.py +++ b/examples/search_with_specific_engine.py @@ -6,19 +6,32 @@ import asyncio from metagpt.roles import Searcher from metagpt.tools.search_engine import SearchEngine, SearchEngineType - +from metagpt.config2 import Config async def main(): question = "What are the most interesting human facts?" - kwargs = {"api_key": "", "cse_id": "", "proxy": None} - # Serper API - # await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPER_GOOGLE, **kwargs)).run(question) - # SerpAPI - # await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPAPI_GOOGLE, **kwargs)).run(question) - # Google API - # await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DIRECT_GOOGLE, **kwargs)).run(question) + + search = Config.default().search + kwargs = {"api_key": search.api_key, "cse_id": search.cse_id, "proxy": None} + + if(search.api_type == SearchEngineType.DIRECT_GOOGLE): + # Google API + await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DIRECT_GOOGLE, **kwargs)).run(question) + elif(search.api_type == SearchEngineType.SERPER_GOOGLE): + # Serper API + await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPER_GOOGLE, **kwargs)).run(question) + elif(search.api_type == SearchEngineType.SERPAPI_GOOGLE): + # SerpAPI + await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPAPI_GOOGLE, **kwargs)).run(question) + else: + # DDG API + await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) + + + + # # DDG API - await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) + # await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) if __name__ == "__main__": From 5caa03d6952b7d69f0cf76df65753181b0b08172 Mon Sep 17 00:00:00 2001 From: Abhishek0075 Date: Wed, 6 Mar 2024 01:41:13 +0530 Subject: [PATCH 3/7] small change --- examples/search_with_specific_engine.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.py index c9fa0395e..5fc17824b 100644 --- a/examples/search_with_specific_engine.py +++ b/examples/search_with_specific_engine.py @@ -27,12 +27,5 @@ async def main(): # DDG API await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) - - - # - # DDG API - # await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) - - if __name__ == "__main__": asyncio.run(main()) From 6ffa22ea335196864aaf57ebbaf32a20519d41bf Mon Sep 17 00:00:00 2001 From: Abhishek0075 Date: Wed, 6 Mar 2024 10:50:31 +0530 Subject: [PATCH 4/7] black reformatting done --- examples/search_with_specific_engine.py | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.py index 5fc17824b..11c9b2315 100644 --- a/examples/search_with_specific_engine.py +++ b/examples/search_with_specific_engine.py @@ -8,24 +8,34 @@ from metagpt.roles import Searcher from metagpt.tools.search_engine import SearchEngine, SearchEngineType from metagpt.config2 import Config + async def main(): question = "What are the most interesting human facts?" - + search = Config.default().search kwargs = {"api_key": search.api_key, "cse_id": search.cse_id, "proxy": None} - - if(search.api_type == SearchEngineType.DIRECT_GOOGLE): + + if search.api_type == SearchEngineType.DIRECT_GOOGLE: # Google API - await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DIRECT_GOOGLE, **kwargs)).run(question) - elif(search.api_type == SearchEngineType.SERPER_GOOGLE): + await Searcher( + search_engine=SearchEngine(engine=SearchEngineType.DIRECT_GOOGLE, **kwargs) + ).run(question) + elif search.api_type == SearchEngineType.SERPER_GOOGLE: # Serper API - await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPER_GOOGLE, **kwargs)).run(question) - elif(search.api_type == SearchEngineType.SERPAPI_GOOGLE): + await Searcher( + search_engine=SearchEngine(engine=SearchEngineType.SERPER_GOOGLE, **kwargs) + ).run(question) + elif search.api_type == SearchEngineType.SERPAPI_GOOGLE: # SerpAPI - await Searcher(search_engine=SearchEngine(engine=SearchEngineType.SERPAPI_GOOGLE, **kwargs)).run(question) + await Searcher( + search_engine=SearchEngine(engine=SearchEngineType.SERPAPI_GOOGLE, **kwargs) + ).run(question) else: # DDG API - await Searcher(search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs)).run(question) - + await Searcher( + search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs) + ).run(question) + + if __name__ == "__main__": asyncio.run(main()) From e4203e54fa802bf01d845dfa588a61a2b92ddbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=98=E6=9D=83=20=E9=A9=AC?= Date: Thu, 7 Mar 2024 11:08:05 +0800 Subject: [PATCH 5/7] feat: +SECURITY.md --- SECURITY.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 000000000..623e6e556 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,14 @@ +# Security Policy + +## Supported Versions + +| Version | Supported | +|---------|--------------------| + | 7.x | :x: | + | 6.x | :x: | +| < 6.x | :x: | + + +## Reporting a Vulnerability + +If you have any vulnerability reports, please contact alexanderwu@deepwisdom.ai . \ No newline at end of file From a5f278c297499fcf596f09d84bb09043ad827dc5 Mon Sep 17 00:00:00 2001 From: Abhishek0075 Date: Thu, 7 Mar 2024 10:51:35 +0530 Subject: [PATCH 6/7] Applied precommit hooks --- examples/debate.py | 18 +++++++++++++----- examples/search_with_specific_engine.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/debate.py b/examples/debate.py index 22cfbf39e..f6c0f1313 100644 --- a/examples/debate.py +++ b/examples/debate.py @@ -5,12 +5,12 @@ Author: garylin2099 @Modified By: mashenquan, 2023-11-1. In accordance with Chapter 2.1.3 of RFC 116, modify the data type of the `send_to` value of the `Message` object; modify the argument type of `get_by_actions`. """ + import asyncio import platform from typing import Any import fire - from metagpt.actions import Action, UserRequirement from metagpt.logs import logger from metagpt.roles import Role @@ -34,7 +34,9 @@ class SpeakAloud(Action): name: str = "SpeakAloud" async def run(self, context: str, name: str, opponent_name: str): - prompt = self.PROMPT_TEMPLATE.format(context=context, name=name, opponent_name=opponent_name) + prompt = self.PROMPT_TEMPLATE.format( + context=context, name=name, opponent_name=opponent_name + ) # logger.info(prompt) rsp = await self._aask(prompt) @@ -66,7 +68,9 @@ class Debator(Role): context = "\n".join(f"{msg.sent_from}: {msg.content}" for msg in memories) # print(context) - rsp = await todo.run(context=context, name=self.name, opponent_name=self.opponent_name) + rsp = await todo.run( + context=context, name=self.name, opponent_name=self.opponent_name + ) msg = Message( content=rsp, @@ -87,7 +91,9 @@ async def debate(idea: str, investment: float = 3.0, n_round: int = 5): team = Team() team.hire([Biden, Trump]) team.invest(investment) - team.run_project(idea, send_to="Biden") # send debate topic to Biden and let him speak first + team.run_project( + idea, send_to="Biden" + ) # send debate topic to Biden and let him speak first await team.run(n_round=n_round) @@ -105,4 +111,6 @@ def main(idea: str, investment: float = 3.0, n_round: int = 10): if __name__ == "__main__": - fire.Fire(main) # run as python debate.py --idea="TOPIC" --investment=3.0 --n_round=5 + fire.Fire( + main + ) # run as python debate.py --idea="TOPIC" --investment=3.0 --n_round=5 diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.py index 11c9b2315..64d5c6e5f 100644 --- a/examples/search_with_specific_engine.py +++ b/examples/search_with_specific_engine.py @@ -4,9 +4,9 @@ """ import asyncio +from metagpt.config2 import Config from metagpt.roles import Searcher from metagpt.tools.search_engine import SearchEngine, SearchEngineType -from metagpt.config2 import Config async def main(): From cbfbecb48767b86beb939fe83e116ecdeb0c4865 Mon Sep 17 00:00:00 2001 From: Abhishek <95518276+Abhishek0075@users.noreply.github.com> Date: Fri, 8 Mar 2024 08:15:13 +0000 Subject: [PATCH 7/7] reformatting done --- examples/debate.py | 17 +++++------------ examples/search_with_specific_engine.py | 24 ++---------------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/examples/debate.py b/examples/debate.py index f6c0f1313..56df16b4f 100644 --- a/examples/debate.py +++ b/examples/debate.py @@ -11,6 +11,7 @@ import platform from typing import Any import fire + from metagpt.actions import Action, UserRequirement from metagpt.logs import logger from metagpt.roles import Role @@ -34,9 +35,7 @@ class SpeakAloud(Action): name: str = "SpeakAloud" async def run(self, context: str, name: str, opponent_name: str): - prompt = self.PROMPT_TEMPLATE.format( - context=context, name=name, opponent_name=opponent_name - ) + prompt = self.PROMPT_TEMPLATE.format(context=context, name=name, opponent_name=opponent_name) # logger.info(prompt) rsp = await self._aask(prompt) @@ -68,9 +67,7 @@ class Debator(Role): context = "\n".join(f"{msg.sent_from}: {msg.content}" for msg in memories) # print(context) - rsp = await todo.run( - context=context, name=self.name, opponent_name=self.opponent_name - ) + rsp = await todo.run(context=context, name=self.name, opponent_name=self.opponent_name) msg = Message( content=rsp, @@ -91,9 +88,7 @@ async def debate(idea: str, investment: float = 3.0, n_round: int = 5): team = Team() team.hire([Biden, Trump]) team.invest(investment) - team.run_project( - idea, send_to="Biden" - ) # send debate topic to Biden and let him speak first + team.run_project(idea, send_to="Biden") # send debate topic to Biden and let him speak first await team.run(n_round=n_round) @@ -111,6 +106,4 @@ def main(idea: str, investment: float = 3.0, n_round: int = 10): if __name__ == "__main__": - fire.Fire( - main - ) # run as python debate.py --idea="TOPIC" --investment=3.0 --n_round=5 + fire.Fire(main) # run as python debate.py --idea="TOPIC" --investment=3.0 --n_round=5 diff --git a/examples/search_with_specific_engine.py b/examples/search_with_specific_engine.py index 64d5c6e5f..1eee762d5 100644 --- a/examples/search_with_specific_engine.py +++ b/examples/search_with_specific_engine.py @@ -6,7 +6,7 @@ import asyncio from metagpt.config2 import Config from metagpt.roles import Searcher -from metagpt.tools.search_engine import SearchEngine, SearchEngineType +from metagpt.tools.search_engine import SearchEngine async def main(): @@ -14,27 +14,7 @@ async def main(): search = Config.default().search kwargs = {"api_key": search.api_key, "cse_id": search.cse_id, "proxy": None} - - if search.api_type == SearchEngineType.DIRECT_GOOGLE: - # Google API - await Searcher( - search_engine=SearchEngine(engine=SearchEngineType.DIRECT_GOOGLE, **kwargs) - ).run(question) - elif search.api_type == SearchEngineType.SERPER_GOOGLE: - # Serper API - await Searcher( - search_engine=SearchEngine(engine=SearchEngineType.SERPER_GOOGLE, **kwargs) - ).run(question) - elif search.api_type == SearchEngineType.SERPAPI_GOOGLE: - # SerpAPI - await Searcher( - search_engine=SearchEngine(engine=SearchEngineType.SERPAPI_GOOGLE, **kwargs) - ).run(question) - else: - # DDG API - await Searcher( - search_engine=SearchEngine(engine=SearchEngineType.DUCK_DUCK_GO, **kwargs) - ).run(question) + await Searcher(search_engine=SearchEngine(engine=search.api_type, **kwargs)).run(question) if __name__ == "__main__":