tool_parser

Module Contents

Classes

ToolStatusCode

Enum where members are also (and must be) ints

ToolParser

InterpreterParser

PluginParser

MixedToolParser

Functions

default_plugin_validate(plugin)

lagent.prompts.parsers.tool_parser.default_plugin_validate(plugin)
参数:

plugin (str) –

class lagent.prompts.parsers.tool_parser.ToolStatusCode

Bases: enum.IntEnum

Enum where members are also (and must be) ints

NO_TOOL = 0
VALID_TOOL = 1
PARSING_ERROR = -1
class lagent.prompts.parsers.tool_parser.ToolParser(tool_type, template='', begin='<tool>\n', end='</tool>\n', validate=None, **kwargs)

Bases: lagent.prompts.parsers.StrParser

参数:
  • tool_type (str) –

  • template (str) –

  • begin (str) –

  • end (str) –

  • validate (Callable[[str], Any]) –

template = ''
tool_type
validate
parse_response(data)
参数:

data (str) –

返回类型:

dict

format_response(parsed)
参数:

parsed (dict) –

返回类型:

str

class lagent.prompts.parsers.tool_parser.InterpreterParser(tool_type='interpreter', template='', begin='<|action_start|><|interpreter|>\n', end='<|action_end|>\n', validate=None, **kwargs)

Bases: ToolParser

参数:
  • tool_type (str) –

  • template (str) –

  • begin (str) –

  • end (str) –

  • validate (Callable[[str], Any]) –

class lagent.prompts.parsers.tool_parser.PluginParser(tool_type='plugin', template='', begin='<|action_start|><|plugin|>\n', end='<|action_end|>\n', validate=default_plugin_validate, **kwargs)

Bases: ToolParser

参数:
  • tool_type (str) –

  • template (str) –

  • begin (str) –

  • end (str) –

  • validate (Callable[[str], Any]) –

class lagent.prompts.parsers.tool_parser.MixedToolParser(tool_type=None, template='', parsers=None, **format_field)

Bases: lagent.prompts.parsers.StrParser

参数:
  • tool_type (Optional[str]) –

  • parsers (List[ToolParser]) –

parsers
tool_type = None
format_instruction()
返回类型:

List[dict]

parse_response(data)
参数:

data (str) –

返回类型:

dict

format_response(parsed)
参数:

parsed (dict) –

返回类型:

str