For consistent LLM behaviour, you can use ollama api with your model of choice to generate. https://docs.ollama.com/api/generate
Chrome has a built-in Gemini Nano too. But there isn't an official way to use it outside chrome yet.