Given $|z|=1$, we can set $z=\cos \theta+i \sin \theta(0 \leqslant \theta<2 \pi)$. Then
$$
\begin{aligned}
f(z) & =\left|(\cos \theta+i \sin \theta)^{3}-(\cos \theta+i \sin \theta)+2\right| \\
& =\sqrt{6+4 \cos 3 \theta-2 \cos 2 \theta-4 \cos \theta} .
\end{aligned}
$$

Using $\cos 3 \theta=4 \cos ^{3} \theta-3 \cos \theta, \cos 2 \theta=2 \cos ^{2} \theta-1$, let $\cos \theta=t$, thus
$$
f(z)=2 \sqrt{(2 t+1)^{2}\left(t-\frac{5}{4}\right)+\frac{13}{4}}(-1 \leqslant t \leqslant 1) \text {. }
$$

Since $t-\frac{5}{4}<0$, we have $(2 t+1)^{2}\left(t-\frac{5}{4}\right)+\frac{13}{4} \leqslant \frac{13}{4}$, equality holds if and only if $t=-\frac{1}{2}$, thus when $t=-\frac{1}{2}$, i.e., $z=-\frac{1}{2} \pm \frac{\sqrt{3}}{2} i$, $f(z)$ reaches its maximum value $2 \sqrt{\frac{13}{4}}=\sqrt{13}$.
If $z$ is a complex number, $|z|=b$, find the maximum value of $f(z)=\left|z^{3}-z+2\right|$.

---

The translation maintains the original format and line breaks as requested.