-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
7 additions
and
7 deletions.
There are no files selected for viewing
11 changes: 5 additions & 6 deletions
11
Projects/2. Large Language Models and LangChain/chat_models.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
llm(messages) # Call the llm object with the list of messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters