!pip install langchain openai python-dotenvChain Exercise
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env filefrom langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
OpenAIModel = "gpt-4"
llm = ChatOpenAI(model=OpenAIModel, temperature=0.1)# @title #### Student Identity
student_id = "your student id" # @param {type:"string"}
name = "your name" # @param {type:"string"}
assignment_id = "00_langchain-exercise"# Intalling Libs
%pip install rggraderSimple Chain
Let’s create a simple chain that will generate a list of movie titles where we can input the movie category and/or movie description.
# @title #### 01. Simple Chain Exercise
from rggrader import submit
# Put your code here:
# ---- End of your code ----
# Submit Method
question_id = "01_simple-langchain-exercise"
submit(student_id, name, assignment_id, str(answer), question_id)Sequential Chain
Let’s create a sequential chain from our previous answer this time we will ask the LLM to create a movie synopsis based on the title. If your previous answer have more than one option, please change the code to return only one answer.
# @title #### 02. Sequential Chain Exercise
from rggrader import submit
# Put your code here:
answer = ""
# ---- End of your code ----
# Submit Method
question_id = "02_sequential-langchain-exercise"
submit(student_id, name, assignment_id, str(answer), question_id)Self Exploration
Can you create more complex chains ?