Let $G$ be a non-bipartite graph of order $n$ without triangles. Then
$|E(G)|\leq\frac{(n-1)^2}{4}+1$.
Proof. Since the graph does not contain triangles, for any edge $uv$ we have $\deg(u)+\deg(v)\leq n$.
The following three cases are possible.
(1) There is a pair of adjacent vertices $u,v$ for which
$\operatorname{deg}u+\operatorname{deg}v=n$.
(2) There is a pair of adjacent vertices $u,v$ for which
$\operatorname{deg}u+\operatorname{deg}v=n-1$.
(3) For any adjacent vertices $u$ and $v$ the inequality
$\operatorname{deg}u+\operatorname{deg}v\leq n-2$ holds.
Consider each case.
(1) If $\operatorname{deg}u+\operatorname{deg}v=n$,
then our graph is bipartite with parts $N(u)$ and $N(v)$,
where $N(x)$ are all neighbors of $x$.
(2) Let $\operatorname{deg}u+\operatorname{deg}v=n-1$ and $w\notin N(u)\cup N(v)$.
If $N(w)\cap N(u)=\varnothing$ or
$N(w)\cap N(v)=\varnothing$, then the graph is bipartite.
If $k=|N(w)\cap N(u)|>0$ and $l=|N(w)\cap N(v)|>0$ and $d=\operatorname{deg}u$,
then since the graph without triangles
$$
|E(G)|\leq \operatorname{deg}u\cdot \operatorname{deg}v+k+l-kl\leq
\operatorname{deg}u\cdot \operatorname{deg}v+1=(n-1)d-d^2+1=
$$
$$
-\left(d-\frac{n-1}{2}\right)^2+\frac{(n-1)^2}{4}+1\leq\frac{(n-1)^2}{4}+1.
$$
(3) If
$\operatorname{deg}u+\operatorname{deg}v\leq n-2$ for any adjacent vertices $u$ and $v$, then
$$
(n-2)|E(G)|\geq\sum_{uv\in E(G)}(\operatorname{deg}u+\operatorname{deg}v)=
\sum_{u\in V(G)}(\operatorname{deg}u)^2\geq
$$
$$
\frac{1}{n}\left(\sum_{u\in V(G)}\operatorname{deg}u\right)^2=\frac{4|E(G)|^2}{n}.
$$
So
$$
|E(G)|\leq\frac{n(n-2)}{4}<\frac{(n-1)^2}{4}.
$$
Addendum (in response to @ZFR's 20.07.2022 questions).
If $uv$ is an edge, $\deg(u)+deg(v)=n-1$, $N(u)\cap N(v)=\varnothing$, $w\notin N(u)\cup N(v)$, and for example $N(w)\cap N(u)=\varnothing$, then the graph is bipartite and its parts are $N(v)$ and $N(u)\cup\{w\}$.
Why does the inequality
$$
|E(G)|\leq\deg(u)\cdot\deg(v)+k+l-kl
$$
hold?
In a graph $G$ there can be only edges connecting vertices of sets $N(u)$ and $N(v)$ except for edges connecting vertices $N(w)\cap N(u)$ and $N(w)\cap N(v)$ (such edges cannot exceed $\deg(u)\cdot\deg(v)-kl$), edges connecting the vertex $w$ with some vertices of $N(u)$ and $N(v)$ (there are exactly $k+l$).
The inequality $k+l-kl\leq1$ follows from the fact that $(k-1)(l-1)\geq0$.