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)[source]

Bases: 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[source]

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

Parameters:

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[source]

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