pymllm.parsers.tool_call_parser =============================== .. py:module:: pymllm.parsers.tool_call_parser .. autoapi-nested-parse:: Tool-call (function-calling) output parser. Extracts structured tool calls from model output text. Supports both one-shot and incremental streaming modes. Formats supported: * **qwen25** — ``{"name":...,"arguments":...}`` * **llama3** — ``<|python_tag|>{"name":...,"parameters":...}`` * **hermes** — ``{"name":...,"arguments":...}`` (same tags, Hermes schema) Usage:: # Non-streaming parser = ToolCallParser("qwen25", tools=tools_list) content, tool_calls = parser.parse_non_stream(full_text) # Streaming parser = ToolCallParser("qwen25", tools=tools_list) for delta in deltas: content_delta, tool_call_deltas = parser.parse_stream_chunk(delta) Classes ------- .. autoapisummary:: pymllm.parsers.tool_call_parser.ToolCallItem pymllm.parsers.tool_call_parser.ToolCallParser Module Contents --------------- .. py:class:: ToolCallItem A single parsed tool call. .. py:attribute:: name :type: Optional[str] :value: None .. py:attribute:: arguments :type: str :value: '' .. py:attribute:: tool_call_id :type: str :value: '' .. py:attribute:: index :type: int :value: 0 .. py:method:: to_openai_dict(streaming = True) Convert to OpenAI ``tool_calls[]`` element format. :param streaming: If True, include ``index`` (streaming delta format). If False, omit ``index`` (non-streaming message format). .. py:class:: ToolCallParser(model_type, tools = None) Model-agnostic tool-call parser. :param model_type: Key into the format registry (e.g. ``"qwen25"``, ``"llama3"``). :param tools: The ``tools`` list from the OpenAI chat request (used to resolve function names). .. py:attribute:: SUPPORTED .. py:method:: has_tool_call(text) Return True if *text* contains a tool-call pattern. .. py:method:: parse_non_stream(text) Parse complete text. Returns ``(remaining_content, tool_calls)``. .. py:method:: parse_stream_chunk(delta) Parse an incremental streaming delta. Returns ``(content_delta, tool_call_items)``. For tool call items: - First item for a call: ``name`` is set, ``arguments`` is ``""``. - Subsequent items: ``name`` is ``None``, ``arguments`` is the new characters appended (argument delta). .. py:method:: flush() Flush any remaining buffered tool call (call at request end).