!pip install langchain openai python-dotenv
Chain Exercise
import os
from dotenv import load_dotenv, find_dotenv
= load_dotenv(find_dotenv()) # read local .env file _
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
= "gpt-4"
OpenAIModel = ChatOpenAI(model=OpenAIModel, temperature=0.1) llm
# @title #### Student Identity
= "your student id" # @param {type:"string"}
student_id = "your name" # @param {type:"string"}
name = "00_langchain-exercise" assignment_id
# Intalling Libs
%pip install rggrader
Simple 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
= "01_simple-langchain-exercise"
question_id str(answer), question_id) submit(student_id, name, assignment_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
= "02_sequential-langchain-exercise"
question_id str(answer), question_id) submit(student_id, name, assignment_id,
Self Exploration
Can you create more complex chains ?