Shortcuts

JSONCallParser

class torchrl.envs.llm.transforms.JSONCallParser[source]

Parser for JSON-style function-calling responses.

Expects responses in the format:
{

“message”: “…”, “tools”: [

{“tool”: “search”, “args”: {“query”: “…”}, “tag”: “A”}, {“tool”: “summarize”, “args”: {“text”: “…”}}

]

}

Examples

>>> parser = JSONCallParser()
>>> response = {
...     "message": "Let me search for that.",
...     "tools": [{"tool": "search", "args": {"query": "torchrl"}}]
... }
>>> result = parser(response)
>>> print(result["text"])
Let me search for that.
>>> print(result["calls"][0].tool)
search

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources