0
0
LangChainframework~10 mins

Connecting to OpenAI models in LangChain - Interactive Code Practice

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

Complete the code to import the OpenAI LLM class from LangChain.

LangChain
from langchain.llms import [1]
Drag options to blanks, or click blank then click option'
AOpenAIClient
BChatOpenAI
COpenAI
DOpenAIModel
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ChatOpenAI' instead of 'OpenAI' for basic model connection.
Trying to import from wrong module.
2fill in blank
medium

Complete the code to create an OpenAI LLM instance with the model name 'text-davinci-003'.

LangChain
llm = OpenAI(model_name=[1])
Drag options to blanks, or click blank then click option'
A'gpt-4'
B'gpt-3.5-turbo'
C'code-cushman-001'
D'text-davinci-003'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPT-4 or GPT-3.5 model names when the example expects 'text-davinci-003'.
Forgetting to put the model name in quotes.
3fill in blank
hard

Fix the error in the code to correctly call the LLM with a prompt string.

LangChain
response = llm([1])
Drag options to blanks, or click blank then click option'
A'Hello, how are you?'
B['Hello, how are you?']
CNone
D123
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list instead of a string as prompt.
Passing a number or None instead of a string.
4fill in blank
hard

Fill both blanks to import the OpenAI class and create an instance with temperature 0.7.

LangChain
from langchain.llms import [1]
llm = [2](temperature=0.7)
Drag options to blanks, or click blank then click option'
AOpenAI
BChatOpenAI
DOpenAIClient
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing import and instance names.
Using 'ChatOpenAI' when 'OpenAI' is expected.
5fill in blank
hard

Fill all three blanks to create an OpenAI LLM with model 'text-davinci-003', temperature 0, and call it with a prompt.

LangChain
llm = OpenAI(model_name=[1], temperature=[2])
response = llm([3])
Drag options to blanks, or click blank then click option'
A'gpt-4'
B0
C'Hello, LangChain!'
D'text-davinci-003'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong model names or wrong data types for parameters.
Passing prompt as a list or number.