update CodeParser.parse_code.

This commit is contained in:
刘棒棒 2024-01-23 17:46:41 +08:00
parent a06d8023d6
commit cff4eff78d
2 changed files with 3 additions and 2 deletions

View file

@ -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}"