Let $S$ be a set, and $F$, $G$ be groups. Let $f: S \rightarrow F$ and $g: S \rightarrow G$ be functions.
I want to prove the following:
If $f(S)$ generates $F$, then there exists at most one homomorphism $\psi:F \rightarrow G$ such that the following diagram commutes.
I know that for every $s \in S$, $\psi(f(s))$ should be defined as $g(s)$, and so $\psi(f(s)^{-1})$ should be defined as $g(s)^{-1}$.
And because $\{f(s): s \in S\} \cup \{f(s)^{-1} : s \in S \}$ is a generating set of $F$, the mapping $\psi$ can be extended to the whole domain $F$ as a homomorphism.
However, in my mind, I understand the processing, but I couldn't write the proof in the clear way.
Please, help me.
Edit 1:
This question is from the section free groups (Lang, Algebra. p. 66)
Before defining the free group, this statement appears.
Edit 2:
I edit the title.
If for some $s_1, s_2 \in S$, $f(s_1) = f(s_2)$ and $g(s_1) \neq g(s_2)$, then there does not exist $\psi$.

So $f$ and $g$ are just given maps between sets and $f$ is injective. If you want the diagram to commute, this defines where $\psi$ maps the generators of $F$. What you have to show is if you have a mapping of the group generators, there is a unique way to extend it to a group homomorphism.
So let $\sigma \in F$ be arbitrary. Then $\sigma$ can be written as $\sigma=a_1^{n_1}\cdot ... \cdot a_k^{n_k}$ where the $a_i$ are generators and the $n_i \in \mathbb{Z}$. Because the group is free, this representation is unique. As we already know $\psi(a_i)$ and want $\psi$ to be a group homomorphism, this defines a unique value for $\psi(\sigma) \in G$. You can check that this definition of $\psi$ actually gives a group homomorphism.