This repository contains code and instructions on creating a simple chatbot using Langchain w/ Google Cloud's Vertex AI platform and the Gemini 1.5 Pro model.
- A Google Cloud Platform (GCP) account with billing enabled.
- Python 3.9 or later installed on your local machine.
- A text editor or IDE of your choice.
- Create a Google Cloud Project:
- If you don't have an existing project, create one in the Google Cloud Console.
- Enable the Vertex AI API:
- Navigate to the Vertex AI section in the console and enable the API if it's not already enabled.
- Create a Service Account:
- Go to the IAM & Admin > Service Accounts section.
- Create a new service account.
- Grant the "Vertex AI User" role to the service account.
- Download the JSON key file for the service account.
- Set Environment Variables:
- Create a
.env
file in the root directory of this repository. - Add the following line, replacing
path/to/your/keyfile.json
with the actual path to your downloaded key file:
GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
- Clone the Repository:
git clone https://github.com/brainiakk/langchain-gemini-test.git
cd langchain-gemini-test
- Install Dependencies:
pip install -r requirements.txt
- Run the Python Script:
python -m main
- Interact with the Chatbot:
- The script will start a loop and prompt you for input.
- Type your query and press Enter.
- The chatbot will respond using the Gemini Pro model.
load_dotenv()
: This line loads environment variables from the.env
file, including the path to your service account key file.llm = ChatVertexAI(...)
: This line initializes theChatVertexAI
object from thevertexai.preview.language_models
library. It specifies the Gemini Pro model and a temperature value for controlling the randomness of the responses.response = llm.invoke(text)
: This line sends the user's input (text
) to the Vertex AI API for processing by the Gemini Pro model.print(response.content)
: This line prints the model's response to the console.
- The code provided is a basic example and can be extended with additional features.
- Refer to the Vertex AI documentation for more advanced usage and customization options.
- Remember to replace
path/to/your/keyfile.json
with the actual path to your service account key file.
This code is provided for educational purposes only.