If the force is not derived from a potential, then the system is said to be polygenic and the Principle of Least Action does not apply. However, the Euler-Lagrange equations can be derived from d'Alembert Principle.
If we decompose the applied (or specified) forces acting on particle $\alpha$ into monogenic (derived from a potential), $\vec F_\alpha^m$ and polygenic forces, $\vec F_\alpha^p$, then d'Alembert Principle reads,
$$\sum_\alpha(\vec F_\alpha^m+\vec F_\alpha^p-\dot{\vec p}_\alpha)\cdot\delta\vec r_\alpha=0.$$
The next step is to write this equation in terms of generalized coordinates $q_i$. The result is the following equation of motion
$$\frac{d}{dt}\frac{\partial T}{\partial \dot q_i}-\frac{\partial T}{\partial q_i}=Q_i^m+Q_i^p,$$
where
$$Q_i^p\equiv\sum_\alpha\vec F_\alpha\cdot\frac{\partial \vec r_\alpha}{\partial q_i}.\tag1$$
The monogenic force can be obtained from a potential $V$,
$$Q_i^m=-\frac{\partial V}{\partial q_i},$$
hence the equation of motion
$$\frac{d}{dt}\frac{\partial T}{\partial \dot q_i}-\frac{\partial T}{\partial q_i}+\frac{\partial V}{\partial q_i}=Q_i^p.$$
If the potential does not depend on velocities, then this equation can also be written as
$$\frac{d}{dt}\frac{\partial L}{\partial \dot q_i}-\frac{\partial L}{\partial q_i}=Q_i^p,\tag2$$
where $L=T-V$ is the Lagrange function. Equation (2) is the one you shall use, together with Eqn. (1) to obtain the generalized force $Q_i^p$.
Edit:
Let's now apply this approach to the example posed in the question. There are two external forces, which can be written as
$\vec F_1 = [F_x(t) \; , 0]^T$ and $\vec F_2 = [0 \; , -F_\theta(t)]^T$. The position of each body (regarded as a point mass) is $\vec r_1 = [x \; , 0]^T$ and $\vec r_2 = [x + l \sin \theta \; , -l \cos \theta]^T$. Therefore, we calculate $$Q_1^p = \vec F_1 \cdot\frac{\partial \vec r_1}{\partial x} + \vec F_2 \cdot\frac{\partial \vec r_2}{\partial x} = F_x(t)$$ and
$$Q_2^p = \vec F_1 \cdot\frac{\partial \vec r_1}{\partial \theta} + \vec F_2 \cdot\frac{\partial \vec r_2}{\partial \theta} = -F_\theta(t) l \sin \theta .$$
Finally, the corresponding Euler-Lagrange equations are
$$\frac{d}{dt}\left(\frac{\partial L}{\partial \dot x}\right )-\frac{\partial L}{\partial x}= F_x(t)$$
$$\frac{d}{dt}\left(\frac{\partial L}{\partial \dot \theta}\right )-\frac{\partial L}{\partial \theta}=-F_\theta(t) l \sin \theta,$$
where $$L = T - V = \frac{M}{2} \left\lVert\dot {\vec r_1}\right\rVert^2 + \frac{m}{2} \left\lVert\dot {\vec r_2}\right\rVert^2 + m g l \cos \theta .$$