The company, known for its electric trucks and SUVs, is racing to catch up to rivals with help from AI.