0
0
LangChainframework~10 mins

LangChain vs direct API calls - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the LangChain OpenAI class.

LangChain
from langchain.llms import [1]
Drag options to blanks, or click blank then click option'
AOpenAIClient
BChatOpenAI
CLangOpenAI
DOpenAI
Attempts:
3 left
💡 Hint
Common Mistakes
Using ChatOpenAI which is for chat models, not direct OpenAI calls.
Trying to import a non-existent class like OpenAIClient.
2fill in blank
medium

Complete the code to create a LangChain OpenAI instance with temperature 0.7.

LangChain
llm = OpenAI(temperature=[1])
Drag options to blanks, or click blank then click option'
A0.7
B1.0
C0
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 which makes output deterministic.
Using None which is invalid for temperature.
3fill in blank
hard

Fix the error in the direct OpenAI API call to generate text.

LangChain
response = client.completions.create(model="text-davinci-003", [1]="Hello, world!", max_tokens=50)
Drag options to blanks, or click blank then click option'
Amessage
Binput_text
Cprompt
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using input_text which is for embeddings.create.
Using message which is for chat.completions.create.
4fill in blank
hard

Fill both blanks to create a LangChain prompt template and generate text.

LangChain
from langchain.prompts import [1]
prompt = [2](template="Say hello to {name}!")
result = llm(prompt.format(name="Alice"))
Drag options to blanks, or click blank then click option'
APromptTemplate
BPrompt
CTemplatePrompt
DPromptFormatter
Attempts:
3 left
💡 Hint
Common Mistakes
Using Prompt which is not a class in LangChain prompts module.
Using TemplatePrompt which does not exist.
5fill in blank
hard

Fill all three blanks to create a direct OpenAI chat call with messages and get the reply.

LangChain
messages = [{"role": [1], "content": [2]]
response = client.chat.completions.create(model="gpt-4o-mini", messages=messages)
reply = response.choices[0].[3]
Drag options to blanks, or click blank then click option'
A"user"
B"Hello, how are you?"
Cmessage.content
D"system"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "system" role for user messages.
Accessing reply as text instead of message.content.