Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created September 2, 2023 20:41
Show Gist options
  • Save fsndzomga/0e042245d276dce25059191f84c34ceb to your computer and use it in GitHub Desktop.
Save fsndzomga/0e042245d276dce25059191f84c34ceb to your computer and use it in GitHub Desktop.
Simple pipeline to explain the LangChain Expression Language
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