You can use the same method but with a more general Jordan block matrix instead of a strictly diagonal matrix.
EXAMPLE
Setup
For example, say you want a matrix with an eigenvalue $\lambda_1 = 10$ with algebraic multiplicity $a_1=3$ and geometric multiplicity $g_1=2.$
Just set up your Jordan block matrix like this:
$$\begin{align*}
J = \begin{pmatrix}
10 & 1 & 0 \\
0 & 10 & 0 \\
0 & 0 & 10
\end{pmatrix}
\end{align*}$$
Verifying algebraic multiplicity
The characteristic polynomial of this matrix is $\det(J - \lambda I) = (10 - \lambda)^3,$ so the algebraic multiplicity of the eigenvalue $\lambda_1=10$ is $a_1 = 3$ as desired.
Verifying geometric multiplicity
The geometric multiplicity of the eigenvalue $\lambda_1=10$ is the dimension of this eigenvalue's eigenspace, that is, the dimension of the solution space $\{ v: (J-10I)v = 0 \}.$
Writing $v$ as its components $v = \left< v_1, v_2, v_3 \right>,$ the equation $(J-10I)v=0$ becomes
$$\begin{align*}
\left< v_2, 0, 0 \right> = \left< 0, 0, 0 \right>
\end{align*}$$
which means the solution space consists of vectors $v=\left< v_1, 0, v_3 \right>$ where $v_1$ and $v_3$ are free variables. The two free variables yield a two-dimensional solution space, as desired.
(At this point it's easy to see intuitively that the off-diagonal $1$ in $J$ forced $v_2=0,$ i.e., each off-diagonal $1$ in a Jordan form matrix decrements the dimension of the corresponding eigenvalue's eigenspace.)
Conjugating
Again, you can conjugate $J$ by your favorite invertible matrix and retain the desired properties.
CASE OF MULTIPLE DISTINCT EIGENVALUES
If you want to use multiple eigenvalues, just create a Jordan block for each one.
For instance, suppose you want a matrix with
an eigenvalue $\lambda_1$ with algebraic multiplicity $a_1=3$ and geometric multiplicity $g_1=1,$
an eigenvalue $\color{blue}{\lambda_2}$ with algebraic multiplicity $a_1=3$ and geometric multiplicity $g_1=2,$
an eigenvalue $\color{red}{\lambda_3}$ with algebraic multiplicity $a_1=3$ and geometric multiplicity $g_1=3.$
Here's the corresponding Jordan block matrix:
$$\begin{align*}
J = \begin{pmatrix}
\lambda_1 & \mathbf 1 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \lambda_1 & \mathbf 1 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \lambda_1 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{blue}{\lambda_2} & \color{blue}{\mathbf{1}} & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{blue}{\lambda_2} & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{blue}{\lambda_2} & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{red}{\lambda_3} & \color{gray} 0 & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{red}{\lambda_3} & \color{gray} 0 \\
\color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{gray} 0 & \color{red}{\lambda_3}
\end{pmatrix}
\end{align*}$$