MCPcopy Index your code
hub / github.com/abetlen/llama-cpp-python / _finish_tool_call_state

Method _finish_tool_call_state

examples/server/server.py:6317–6350  ·  view source on GitHub ↗
(
        self,
        item_state: Dict[str, Any],
        item_plan: Dict[str, Any],
    )

Source from the content-addressed store, hash-verified

6315 return True, deltas
6316
6317 def _finish_tool_call_state(
6318 self,
6319 item_state: Dict[str, Any],
6320 item_plan: Dict[str, Any],
6321 ) -> Optional[Dict[str, Any]]:
6322 if item_plan["kind"] == "buffered":
6323 parsed_item = self._parse_response_value(
6324 item_state["buffer"],
6325 item_plan["schema"],
6326 partial=False,
6327 )
6328 return self._normalize_tool_call_item(parsed_item, partial=False)
6329 if item_plan["kind"] == "json-message":
6330 if item_state["mode"] != "arguments":
6331 return None
6332 if item_state["pending"] or not item_state["json_started"] or not item_state["json_complete"]:
6333 return None
6334 try:
6335 arguments = self._parse_response_value(
6336 item_state["arguments_text"],
6337 item_plan["arguments_schema"],
6338 partial=False,
6339 )
6340 except CompletionResponseParsingError:
6341 return None
6342 if arguments is None:
6343 return None
6344 item_state["tool_call"]["function"]["arguments"] = arguments
6345 return cast(Dict[str, Any], item_state["tool_call"])
6346 if item_state["pending"] or item_state["current_parameter"] is not None:
6347 return None
6348 if item_state["mode"] not in {"done", "after-function-header"}:
6349 return None
6350 return cast(Dict[str, Any], item_state["tool_call"])
6351
6352 def _tool_call_delta(
6353 self,

Callers 1

_advance_stream_stateMethod · 0.95

Calls 2

_parse_response_valueMethod · 0.95

Tested by

no test coverage detected