def _update_tool_calls(
    tool_calls: List[Dict[str, Any]], tool_calls_delta: Optional[List[Dict[str, Any]]]
) -> List[Dict[str, Any]]:
    """
    Update the tool calls using delta objects received from stream chunks.

    Args:
        tool_calls: The list of existing tool calls.
        tool_calls_delta: The delta updates for the tool calls (if any).

    Returns:
        The updated list of tool calls.

    """
    if not tool_calls_delta:
        return tool_calls

    delta_call = tool_calls_delta[0]
    if not tool_calls or tool_calls[-1].get("index") != delta_call.get("index"):
        tool_calls.append(delta_call)
    else:
        latest_call = tool_calls[-1]
        latest_function = latest_call.setdefault("function", {})
        delta_function = delta_call.get("function", {})

        latest_function["arguments"] = latest_function.get(
            "arguments", ""
        ) + delta_function.get("arguments", "")
        latest_function["name"] = latest_function.get("name", "") + delta_function.get(
            "name", ""
        )
        latest_call["id"] = latest_call.get("id", "") + delta_call.get("id", "")

    return tool_calls

    Update the tool calls using delta objects received from stream chunks.

    Args:
        tool_calls: The list of existing tool calls.
        tool_calls_delta: The delta updates for the tool calls (if any).

    Returns:
        The updated list of tool calls.

    
llama-index-integrations/llms/llama-index-llms-oci-data-science/llama_index/llms/oci_data_science/utils.py