Short answer: CO2 is nonpolar, OF2 is polar
CO2 has a linear molecular geometry with two polar C=O bonds oriented in opposite directions. The electronegativity difference between carbon (2.55) and oxygen (3.44) creates a significant dipole moment for each C=O bond, resulting in a polar molecule. However, the linear geometry of CO2 symmetrically arranges the polar bonds, canceling out the net dipole moment of the molecule. CO2 is therefore nonpolar.
OF2 has a V-shaped molecular geometry with one central atom (oxygen) bonded to two fluorine atoms at an angle of 103 degrees. The electronegativity difference between fluorine (3.98) and oxygen (3.44) creates two polar O-F bonds that are oriented in different directions, resulting in a net dipole moment for the entire molecule. OF2 is therefore polar.