🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
fix: now support parsing code in message.content when using tools_call.
刘棒棒987eb6d38be5
diff --git a/metagpt/provider/openai_api.py b/metagpt/provider/openai_api.pyindex 3358b3aad..dad44087c 100644--- a/metagpt/provider/openai_api.py+++ b/metagpt/provider/openai_api.py@@ -31,6 +31,7 @@ from metagpt.provider.base_llm import BaseLLMfrom metagpt.provider.constant import GENERAL_FUNCTION_SCHEMAfrom metagpt.provider.llm_provider_registry import register_providerfrom metagpt.schema import Message+from metagpt.utils.common import CodeParserfrom metagpt.utils.cost_manager import Costsfrom metagpt.utils.exceptions import handle_exceptionfrom metagpt.utils.token_counter import (@@ -247,6 +248,11 @@ class OpenAILLM(BaseLLM):)return self._parse_arguments(message.tool_calls[0].function.arguments)elif message.tool_calls is None and message.content is not None:+ # reponse is code, fix openai tools_call respond bug.+ code_formats = ("```", '"""', "'''")+ if message.content.startswith(code_formats) and message.content.endswith(code_formats):+ code = CodeParser.parse_code(None, message.content)+ return {"language": "python", "code": code}# reponse is messagereturn {"language": "markdown", "code": self.get_choice_text(rsp)}else: