From e33e0cd2bb78c4b5faeffccea63fcdc677aff8d6 Mon Sep 17 00:00:00 2001 From: DJ Papzin Date: Wed, 14 Aug 2024 17:12:26 +0200 Subject: [PATCH] Add python-dotenv --- .../chat_models.py | 11 +++++------ Projects/requirements.txt | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Projects/2. Large Language Models and LangChain/chat_models.py b/Projects/2. Large Language Models and LangChain/chat_models.py index dadd09b..7e7671e 100644 --- a/Projects/2. Large Language Models and LangChain/chat_models.py +++ b/Projects/2. Large Language Models and LangChain/chat_models.py @@ -1,19 +1,18 @@ -from langchain.chat_models import ChatGemini # Import ChatGemini instead of ChatOpenAI +from langchain_google_genai import GoogleGenerativeAI # Import GoogleGenerativeAI from langchain_google_genai from langchain.schema import ( # Import HumanMessage and SystemMessage from langchain.schema HumanMessage, SystemMessage ) -import getpass +from dotenv import load_dotenv # Import load_dotenv import os -if "GEMINI_API_KEY" not in os.environ: - os.environ["GEMINI_API_KEY"] = getpass.getpass("Provide your GEMINI API Key") +load_dotenv() # Load environment variables from .env file -chat = ChatGemini(model_name="gemini-1.5-pro-exp-0801", temperature=0) # Create a ChatGemini object with the specified model name and temperature +llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=os.getenv("GOOGLE_API_KEY")) # Create GoogleGenerativeAI instance messages = [ # Create a list of messages SystemMessage(content="You are a helpful assistant that translates English to French."), # Create a SystemMessage with the content "You are a helpful assistant that translates English to French." HumanMessage(content="Translate the following sentence: I love programming.") # Create a HumanMessage with the content "Translate the following sentence: I love programming." ] -chat(messages) # Call the chat object with the list of messages \ No newline at end of file +llm(messages) # Call the llm object with the list of messages \ No newline at end of file diff --git a/Projects/requirements.txt b/Projects/requirements.txt index 6ec6f2a..111b603 100644 --- a/Projects/requirements.txt +++ b/Projects/requirements.txt @@ -7,4 +7,5 @@ streamlit==1.23.1 beautifulsoup4==4.11.2 audio-recorder-streamlit==0.0.8 streamlit-chat==0.0.2.2 -langchain-google-genai \ No newline at end of file +langchain-google-genai +python-dotenv \ No newline at end of file