Skip to main content
您当前所在的页面介绍的是 Google models as text completion models. Many popular Google models are chat completion models.You may be looking for 此页面.
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 并生成 API 密钥。 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 setting types.