agentscope.parsers.code_block_parser module

Model response parser class for Markdown code block.

class agentscope.parsers.code_block_parser.MarkdownCodeBlockParser(language_name: str, content_hint: str | None = None)[源代码]

基类:ParserBase

The base class for parsing the response text by fenced block.

tag_end: str = '```'

The ending tag.

__init__(language_name: str, content_hint: str | None = None) None[源代码]

Initialize the parser with the language name and the optional content hint.

参数:

language_name – The name of the language, which will be used in ```{language_name}

name: str = '{language_name} block'

The name of the parser.

tag_begin: str = '```{language_name}'

The beginning tag.

content_hint: str = '${{your_{language_name}_code}}'

The hint of the content.

format_instruction: str = 'You should generate {language_name} code in a {language_name} fenced code block as follows: \n```{language_name}\n{content_hint}\n```'

The instruction for the format of the code block.

parse(response: ModelResponse) ModelResponse[源代码]

Extract the content between the tag_begin and tag_end in the response and store it in the parsed field of the response object.