Skip to content

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

remove langchain parser.

geekanbd9d6e94674f
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index f74d2d8b7..739addc95 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -12,9 +12,6 @@ import re
from typing import Union, List, Tuple
from metagpt.logs import logger
-from langchain.schema import AgentAction, AgentFinish, OutputParserException
-
-FINAL_ANSWER_ACTION = "Final Answer:"
def check_cmd_exists(command) -> int:
@@ -233,33 +230,3 @@ def print_members(module, indent=0):
print(f'{prefix}Function: {name}')
elif inspect.ismethod(obj):
print(f'{prefix}Method: {name}')
-
-
-class BasicParser:
- def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
- if FINAL_ANSWER_ACTION in text:
- return AgentFinish(
- {"output": text.split(FINAL_ANSWER_ACTION)[-1].strip()}, text
- )
- # \s matches against tab/newline/whitespace
- regex = (
- r"Action\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)"
- )
- match = re.search(regex, text, re.DOTALL)
- if not match:
- raise OutputParserException(f"Could not parse LLM output: `{text}`")
- action = match.group(1).strip()
- action_input = match.group(2)
- return AgentAction(action, action_input.strip(" ").strip('"'), text)
-
-
-if __name__ == '__main__':
- parser = BasicParser()
- action_sample = "I need to calculate the 0.23 power of Elon Musk's current age.\nAction: Calculator\nAction Input: 49 raised to the 0.23 power"
- final_answer_sample = "I now know the answer to the question.\nFinal Answer: 2.447626228522259"
-
- rsp = parser.parse(action_sample)
- logger.info(rsp)
-
- rsp = parser.parse(final_answer_sample)
- logger.info(rsp)
diff --git a/tests/metagpt/test_parser.py b/tests/metagpt/test_parser.py
deleted file mode 100644
index 001641a38..000000000
--- a/tests/metagpt/test_parser.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-"""
-@Time : 2023/5/26 20:54
-@Author : alexanderwu
-@File : test_parser.py
-"""
-from langchain.schema import AgentAction, AgentFinish, OutputParserException
-from metagpt.parsers import BasicParser
-
-def test_basic_parser():
- parser = BasicParser()
- action_sample = "I need to calculate the 0.23 power of Elon Musk's current age.\nAction: Calculator\nAction Input: 49 raised to the 0.23 power"
- final_answer_sample = "I now know the answer to the question.\nFinal Answer: 2.447626228522259"
-
- rsp = parser.parse(action_sample)
- assert isinstance(rsp, AgentAction)
-
- rsp = parser.parse(final_answer_sample)
- assert isinstance(rsp, AgentFinish)