Skip to main content
You are currently on a page documenting the use of Google models as text completion models. Many popular Google models are chat completion models.You may be looking for this page instead.
A guide on using Google Generative AI models with LangChain. Note: It’s separate from Google Cloud Vertex AI integration.

Setting up

To use Google Generative AI you must install the langchain-google-genai Python package and generate an API key. Read more details.

Using in a chain

Streaming calls

Safety settings

Gemini models have default safety settings that can be overridden. If you are receiving lots of “Safety Warnings” from your models, you can try tweaking the safety_settings attribute of the model. For example, to turn off safety blocking for dangerous content, you can construct your LLM as follows:
For an enumeration of the categories and thresholds available, see Google’s safety settings guide.