There are ways to greatly improve chances that AI will be beneficial to humanity rather than otherwise.
Check out:
UC Berkeley's Center for Human-Compatible AI, led by Prof. Stuart Russell, a co-author of the field's standard textbook. [1] He just gave a TED talk on the issue [2].
Several other noted researchers in AI are working on the issue as well.