Suppose $X,Y$ are varieties over $\mathbb{C}$, $Y$ is smooth and $X$ is Gorenstein ($X$ is not smooth in my case). Let $f: X \to Y$ be an affine morphism, and each fibre of $f$ has the same dimension $n$. Moreover, $f$ can be assumed to be flat.
For $F \in D^b(X)$ and $G \in D^b(Y)$, I expect to have a Grothendieck-Verdier duality: $${\rm R}f_* {\rm R}\mathcal{H}om(F, f^!(G)) \cong {\rm R}\mathcal{H}om({\rm R}f_*F, G).$$
However, I don't know how to define the functor $f^!$ here.
I have checked the book "Residue and Duality" by Hartshorne, it seems that he requires $f$ at least to be proper in order to define the duality. Besides, in the book "Fourier-Mukai Transforms in Algebraic Geometry" by Huybrechts (c.f. Theorem 3.34 page 86), he did not require $f$ to be proper, but both $X$ and $Y$ are required to be smooth. So I don't know how to establish the duality in my affine setting.
Any suggestion is welcome!!