0
0
LangChainframework~10 mins

Connecting to Anthropic Claude 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 Anthropic class from langchain.llms.anthropic.

LangChain
from langchain.llms.anthropic import [1]
Drag options to blanks, or click blank then click option'
ALangchainAnthropic
BClaude
CAnthropicClient
DAnthropic
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a wrong class name like 'Claude' or 'AnthropicClient'.
Forgetting to import from the correct module path.
2fill in blank
medium

Complete the code to create an Anthropic client with the API key stored in the environment variable.

LangChain
client = Anthropic(api_key=[1])
Drag options to blanks, or click blank then click option'
Aos.environ['API_KEY']
Bos.getenv('ANTHROPIC_API_KEY')
C'ANTHROPIC_API_KEY'
Dgetenv('ANTHROPIC_KEY')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the environment variable name as a string instead of its value.
Using the wrong environment variable name.
3fill in blank
hard

Fix the error in the code to call the Anthropic client to generate text with the prompt.

LangChain
response = client.[1](['Hello, Claude!'])
Drag options to blanks, or click blank then click option'
Agenerate
Bcall
Cgenerate_text
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'generate_text' or 'run'.
Confusing with other library method names.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each prompt to its generated text if the prompt length is greater than 5.

LangChain
results = {prompt: client.[1]([prompt]) for prompt in prompts if len(prompt) [2] 5}
Drag options to blanks, or click blank then click option'
Agenerate
B>
C<
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong method name or comparison operator.
Confusing '<' with '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase prompts to their generated text if the prompt length is less than 10.

LangChain
results = {prompt.[1](): client.[2]([prompt]) for prompt in prompts if len(prompt) [3] 10}
Drag options to blanks, or click blank then click option'
Aupper
Bgenerate
C<
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lower' instead of 'upper' for keys.
Using '>' instead of '<' in the condition.