agentscope.parsers.json_object_parser module
The parser for JSON object in the model response.
- class MarkdownJsonDictParser(content_hint: Any | None = None, required_keys: List[str] | None = None, keys_to_memory: str | bool | Sequence[str] = True, keys_to_content: str | bool | Sequence[str] = True, keys_to_metadata: str | bool | Sequence[str] = False)[source]
Bases:
MarkdownJsonObjectParser
,DictFilterMixin
A class used to parse a JSON dictionary object in a markdown fenced code
- parse(response: ModelResponse) ModelResponse [source]
Parse the text field of the response to a JSON dictionary object, store it in the parsed field of the response object, and check if the required keys exists.
- content_hint: str = '{your_json_dictionary}'
The hint of the content.
- property format_instruction: str
Get the format instruction for the json object, if the format_example is provided, it will be used as the example.
- name: str = 'json block'
The name of the parser.
- required_keys: List[str]
A list of required keys in the JSON dictionary object. If the response misses any of the required keys, it will raise a RequiredFieldNotFoundError.
- tag_begin: str = '```json'
Opening tag for a code block.
- tag_end: str = '```'
Closing end for a code block.
- class MarkdownJsonObjectParser(content_hint: Any | None = None)[source]
Bases:
ParserBase
A parser to parse the response text to a json object.
- parse(response: ModelResponse) ModelResponse [source]
Parse the response text to a json object, and fill it in the parsed field in the response object.
- content_hint: str = '{your_json_object}'
The hint of the content.
- property format_instruction: str
Get the format instruction for the json object, if the format_example is provided, it will be used as the example.
- name: str = 'json block'
The name of the parser.
- tag_begin: str = '```json'
Opening tag for a code block.
- tag_end: str = '```'
Closing end for a code block.