Created
September 2, 2023 20:41
-
-
Save fsndzomga/0e042245d276dce25059191f84c34ceb to your computer and use it in GitHub Desktop.
Simple pipeline to explain the LangChain Expression Language
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
from langchain.prompts import ChatPromptTemplate | |
from langchain.chat_models import ChatOpenAI | |
from apikey import OPENAI_API_KEY | |
import os | |
os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY | |
model = ChatOpenAI() | |
prompt = ChatPromptTemplate.from_template("In 2016, who was the president of {country}") | |
chain = prompt | model | |
countries = ["United States of America", "France", "Poland", "Cameroon"] | |
for country in countries: | |
response = chain.invoke({"country": country}) | |
print(response.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment