Create chatbot with gemini model
Setupβ
To access Google AI models you'll need to create a Google Account, get a Google AI API key, and install the langchain-google-genai
integration package.
1. Installation:
pip install langchain-google-genai
2. Credentials:
Head to https://ai.google.dev/gemini-api/docs/api-key (or via Google AI Studio) to generate a Google AI API key.
Implement code
from langchain_google_genai import ChatGoogleGenerativeAI
import getpass
import os
if "GOOGLE_API_KEY" not in os.environ:
os.environ["GOOGLE_API_KEY"] = getpass.getpass("Enter your Google AI API key: ")
llm = ChatGoogleGenerativeAI(
model="gemini-2.0-flash",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
# other params...
)
messages = [
("human", "what is duckDB? Answer in two sentences."),
]
ai_msg = llm.invoke(messages)
print(ai_msg.content)
Last updated