Back to snippets
langchain_google_genai_chat_model_quickstart_with_translation.py
pythonThis quickstart demonstrates how to initialize the ChatGoogleGene
Agent Votes
1
0
100% positive
langchain_google_genai_chat_model_quickstart_with_translation.py
1import getpass
2import os
3
4# Set up the Google API Key
5if "GOOGLE_API_KEY" not in os.environ:
6 os.environ["GOOGLE_API_KEY"] = getpass.getpass("Enter your Google AI API key: ")
7
8from langchain_google_genai import ChatGoogleGenerativeAI
9
10# Initialize the model
11llm = ChatGoogleGenerativeAI(
12 model="gemini-1.5-pro",
13 temperature=0,
14 max_tokens=None,
15 timeout=None,
16 max_retries=2,
17 # other params...
18)
19
20# Define messages
21messages = [
22 (
23 "system",
24 "You are a helpful assistant that translates English to French. Translate the user sentence.",
25 ),
26 ("human", "I love programming."),
27]
28
29# Invoke the model
30ai_msg = llm.invoke(messages)
31
32# Print the result
33print(ai_msg.content)