Requirement already satisfied: rggrader in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (0.1.6)
Requirement already satisfied: requests in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from rggrader) (2.31.0)
Requirement already satisfied: pandas in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from rggrader) (2.1.0)
Requirement already satisfied: Pillow in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from rggrader) (10.0.0)
Requirement already satisfied: numpy>=1.23.2 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from pandas->rggrader) (1.25.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from pandas->rggrader) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from pandas->rggrader) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from pandas->rggrader) (2023.3)
Requirement already satisfied: charset-normalizer<4,>=2 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from requests->rggrader) (3.2.0)
Requirement already satisfied: idna<4,>=2.5 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from requests->rggrader) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from requests->rggrader) (2.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from requests->rggrader) (2023.7.22)
Requirement already satisfied: six>=1.5 in /Users/ruangguru/Projects/ai-bootcamp/env/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->rggrader) (1.16.0)
Note: you may need to restart the kernel to use updated packages.
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 Exercisefrom rggrader import submit# Put your code here:from langchain.chains import LLMChainprompt = ChatPromptTemplate.from_template("What is the best movie title to describe \ a movie category {category}?, please give 1 name in unorder list")chain = LLMChain(llm=llm, prompt=prompt)product ="Action Comedy featuring Three Mice Musketeers"answer = chain.run(product)print(answer)# ---- End of your code ----# Submit Methodquestion_id ="01_simple-langchain-exercise"submit(student_id, name, assignment_id, str(answer), question_id)
1. "Furrious Adventures: The Three Mice Musketeers"
'Assignment successfully submitted'
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 Exercisefrom rggrader import submit# Put your code here:from langchain.chains import SimpleSequentialChain# prompt template 2second_prompt = ChatPromptTemplate.from_template("Write a 20 words synopsis for the following \ movie title:{title}")# chain 2chain_two = LLMChain(llm=llm, prompt=second_prompt, verbose=True)overall_simple_chain = SimpleSequentialChain(chains=[chain, chain_two],verbose=False)answer = overall_simple_chain.run(product)print(answer)# ---- End of your code ----# Submit Methodquestion_id ="02_sequential-langchain-exercise"submit(student_id, name, assignment_id, str(answer), question_id)
> Entering new LLMChain chain...
Prompt after formatting:
Human: Write a 20 words synopsis for the following movie title:1. "Furrious Furry: The Three Mice Musketeers"
> Finished chain.
Three brave mice embark on a thrilling adventure, using their wit and courage to save their kingdom from a menacing cat.