mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-08 15:05:17 +02:00
update CodeParser.parse_code.
This commit is contained in:
parent
a06d8023d6
commit
cff4eff78d
2 changed files with 3 additions and 2 deletions
|
|
@ -251,7 +251,7 @@ class OpenAILLM(BaseLLM):
|
|||
# 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, start_ends=r'["\'`]{3}')
|
||||
code = CodeParser.parse_code(None, message.content)
|
||||
return {"language": "python", "code": code}
|
||||
# reponse is message
|
||||
return {"language": "markdown", "code": self.get_choice_text(rsp)}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
Add generic class-to-string and object-to-string conversion functionality.
|
||||
@Modified By: mashenquan, 2023/11/27. Bug fix: `parse_recipient` failed to parse the recipient in certain GPT-3.5
|
||||
responses.
|
||||
@Modified By: liubangbang, 2024/01/23. Update: support [```, ''', \"\"\" ] codes in CodeParser.parse_code.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
@ -264,7 +265,7 @@ class CodeParser:
|
|||
return block_dict
|
||||
|
||||
@classmethod
|
||||
def parse_code(cls, block: str, text: str, lang: str = "", start_ends: str = "```") -> str:
|
||||
def parse_code(cls, block: str, text: str, lang: str = "", start_ends: str = r'["\'`]{3}') -> str:
|
||||
if block:
|
||||
text = cls.parse_block(block, text)
|
||||
pattern = rf"{start_ends}{lang}.*?\s+(.*?){start_ends}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue