I have built basic RAG system using REST posts to the OpenAPI endpoints. But have a recent hackathon for my current employer I wanted to play with LangChain. I have gemini pro and an API key I used for my API requests, but it wasn't working for the LangChain tutorial. A little bit of google searching got it working.

In my Juypter Notebook, I install the python packages

%pip install langchain langchain-core langchain-community langchain-google-genai pillow

Then use this chain to give it a test run

import getpass
import os
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate

# env
os.environ["LANGCHAIN_TRACING_V2"] = "false"
os.environ["GOOGLE_API_KEY"] = "KEY_HERE"

# template
prompt_template = ChatPromptTemplate.from_messages(
        [
                ("system", "translate the following into {language}"),
                ("user", "{text}")
        ]
)

# chain
model = ChatGoogleGenerativeAI(model="gemini-pro", convert_system_message_to_human=True)
parser = StrOutputParser()
chain = prompt_template | model | parser

# print
print(chain.invoke({"language": "italian", "text": "hi"}))

The official LangChain docs directed me to from langchain_google_vertexai import ChatVertexAI, but that wanted some more than just my Gemini Pro Key. It wanted credentials for google cloud and I didn't want to go there just yet. So anyone else out there having a problem, hope this helps.