From ba8bf018708ca96c954834eaa53a1997f7f5158b Mon Sep 17 00:00:00 2001 From: geekan Date: Tue, 26 Dec 2023 16:39:19 +0800 Subject: [PATCH] remove code --- metagpt/provider/base_chatbot.py | 9 -------- metagpt/provider/base_gpt_api.py | 25 +-------------------- metagpt/provider/human_provider.py | 8 ------- tests/metagpt/provider/test_base_gpt_api.py | 5 ----- tests/metagpt/test_gpt.py | 8 ------- 5 files changed, 1 insertion(+), 54 deletions(-) diff --git a/metagpt/provider/base_chatbot.py b/metagpt/provider/base_chatbot.py index 535130de7..8d490f1a6 100644 --- a/metagpt/provider/base_chatbot.py +++ b/metagpt/provider/base_chatbot.py @@ -14,17 +14,8 @@ from dataclasses import dataclass class BaseChatbot(ABC): """Abstract GPT class""" - mode: str = "API" use_system_prompt: bool = True @abstractmethod def ask(self, msg: str, timeout=3) -> str: """Ask GPT a question and get an answer""" - - @abstractmethod - def ask_batch(self, msgs: list, timeout=3) -> str: - """Ask GPT multiple questions and get a series of answers""" - - @abstractmethod - def ask_code(self, msgs: list, timeout=3) -> str: - """Ask GPT multiple questions and get a piece of code""" diff --git a/metagpt/provider/base_gpt_api.py b/metagpt/provider/base_gpt_api.py index cae55431f..e6b180eaa 100644 --- a/metagpt/provider/base_gpt_api.py +++ b/metagpt/provider/base_gpt_api.py @@ -60,16 +60,6 @@ class BaseGPTAPI(BaseChatbot): def _extract_assistant_rsp(self, context): return "\n".join([i["content"] for i in context if i["role"] == "assistant"]) - def ask_batch(self, msgs: list, timeout=3) -> str: - context = [] - for msg in msgs: - umsg = self._user_msg(msg) - context.append(umsg) - rsp = self.completion(context, timeout=timeout) - rsp_text = self.get_choice_text(rsp) - context.append(self._assistant_msg(rsp_text)) - return self._extract_assistant_rsp(context) - async def aask_batch(self, msgs: list, timeout=3) -> str: """Sequential questioning""" context = [] @@ -80,17 +70,12 @@ class BaseGPTAPI(BaseChatbot): context.append(self._assistant_msg(rsp_text)) return self._extract_assistant_rsp(context) - def ask_code(self, msgs: list[str], timeout=3) -> str: - """FIXME: No code segment filtering has been done here, and all results are actually displayed""" - rsp_text = self.ask_batch(msgs, timeout=timeout) - return rsp_text - async def aask_code(self, msgs: list[str], timeout=3) -> str: """FIXME: No code segment filtering has been done here, and all results are actually displayed""" rsp_text = await self.aask_batch(msgs, timeout=timeout) return rsp_text - def completion(self, messages: list[dict], timeout=3): + def completion(self, messages: list[dict], timeout=3) -> dict: """All GPTAPIs are required to provide the standard OpenAI completion interface [ {"role": "system", "content": "You are a helpful assistant."}, @@ -157,11 +142,3 @@ class BaseGPTAPI(BaseChatbot): {'language': 'python', 'code': "print('Hello, World!')"} """ return json.loads(self.get_choice_function(rsp)["arguments"]) - - def messages_to_prompt(self, messages: list[dict]): - """[{"role": "user", "content": msg}] to user: etc.""" - return "\n".join([f"{i.role}: {i.content}" for i in messages]) - - def messages_to_dict(self, messages): - """objects to [{"role": "user", "content": msg}] etc.""" - return [i.to_dict() for i in messages] diff --git a/metagpt/provider/human_provider.py b/metagpt/provider/human_provider.py index 5850dd8dc..a90c78192 100644 --- a/metagpt/provider/human_provider.py +++ b/metagpt/provider/human_provider.py @@ -31,10 +31,6 @@ class HumanProvider(BaseGPTAPI): ) -> str: return self.ask(msg, timeout=timeout) - def completion(self, messages: list[dict], timeout=3): - """dummy implementation of abstract method in base""" - return [] - async def acompletion(self, messages: list[dict], timeout=3): """dummy implementation of abstract method in base""" return [] @@ -42,7 +38,3 @@ class HumanProvider(BaseGPTAPI): async def acompletion_text(self, messages: list[dict], stream=False, timeout=3) -> str: """dummy implementation of abstract method in base""" return "" - - async def close(self): - """Close connection""" - pass diff --git a/tests/metagpt/provider/test_base_gpt_api.py b/tests/metagpt/provider/test_base_gpt_api.py index 8628608a9..0bee0ce75 100644 --- a/tests/metagpt/provider/test_base_gpt_api.py +++ b/tests/metagpt/provider/test_base_gpt_api.py @@ -47,11 +47,6 @@ def test_base_gpt_api(): assert "user" in str(message) base_gpt_api = MockBaseGPTAPI() - msg_prompt = base_gpt_api.messages_to_prompt([message]) - assert msg_prompt == "user: hello" - - msg_dict = base_gpt_api.messages_to_dict([message]) - assert msg_dict == [{"role": "user", "content": "hello"}] openai_funccall_resp = { "choices": [ diff --git a/tests/metagpt/test_gpt.py b/tests/metagpt/test_gpt.py index 1884dd54b..caa1eb277 100644 --- a/tests/metagpt/test_gpt.py +++ b/tests/metagpt/test_gpt.py @@ -23,14 +23,6 @@ class TestGPT: answer = llm_api.ask_batch(["请扮演一个Google Python专家工程师,如果理解,回复明白", "写一个hello world"], timeout=60) assert len(answer) > 0 - def test_llm_api_ask_code(self, llm_api): - try: - answer = llm_api.ask_code(["请扮演一个Google Python专家工程师,如果理解,回复明白", "写一个hello world"]) - logger.info(answer) - assert len(answer) > 0 - except openai.BadRequestError: - assert CONFIG.OPENAI_API_TYPE == "azure" - @pytest.mark.asyncio async def test_llm_api_aask(self, llm_api): answer = await llm_api.aask("hello chatgpt", stream=False)