0
0
LangChainframework~20 mins

Connecting to open-source models in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Open-Source Model Connector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ component_behavior
intermediate
2:00remaining
What is the output of this LangChain code connecting to an open-source model?

Consider this Python code using LangChain to connect to an open-source model with HuggingFaceHub. What will be printed?

LangChain
from langchain import HuggingFaceHub

repo_id = "google/flan-t5-small"
hf = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature":0})

response = hf.predict("Translate English to French: 'Hello, how are you?'" )
print(response)
A"Bonjour, comment รงa va ?"
B"Hello, how are you?"
CSyntaxError due to missing import
DTypeError because predict method does not exist
Attempts:
2 left
๐Ÿ’ก Hint

Think about what the model is designed to do and what the predict method returns.

๐Ÿ“ Syntax
intermediate
2:00remaining
Which option correctly initializes a LangChain HuggingFaceHub client for an open-source model?

Choose the correct way to create a HuggingFaceHub instance for the model "facebook/bart-large-cnn" with temperature 0.7.

AHuggingFaceHub(model_id="facebook/bart-large-cnn", temperature=0.7)
BHuggingFaceHub(repo_id="facebook/bart-large-cnn", model_kwargs={"temperature":0.7})
CHuggingFaceHub(repo="facebook/bart-large-cnn", model_kwargs={temperature:0.7})
DHuggingFaceHub(repo_id="facebook/bart-large-cnn", temperature=0.7)
Attempts:
2 left
๐Ÿ’ก Hint

Check the parameter names and how model_kwargs is passed as a dictionary.

๐Ÿ”ง Debug
advanced
2:00remaining
What error does this LangChain code raise when connecting to an open-source model?

Analyze this code snippet and identify the error it will raise.

LangChain
from langchain import HuggingFaceHub

hf = HuggingFaceHub(repo_id="google/flan-t5-small")
response = hf.predict()
print(response)
AValueError: repo_id not found
BAttributeError: 'HuggingFaceHub' object has no attribute 'predict'
CRuntimeError: Model loading failed
DTypeError: predict() missing 1 required positional argument: 'input'
Attempts:
2 left
๐Ÿ’ก Hint

Check the method signature of predict and what arguments it requires.

โ“ state_output
advanced
2:00remaining
What is the value of the variable 'output' after running this LangChain code?

Given this code connecting to an open-source model, what will output contain?

LangChain
from langchain import HuggingFaceHub

hf = HuggingFaceHub(repo_id="google/flan-t5-small", model_kwargs={"temperature":0})
output = hf.predict("Summarize: LangChain is a framework for building applications with LLMs.")
A"LangChain is a framework to build applications using large language models."
B"LangChain is a tool for data visualization."
C"Error: Model not found"
D"LangChain is a programming language."
Attempts:
2 left
๐Ÿ’ก Hint

Think about what the model is expected to do with the input prompt.

๐Ÿง  Conceptual
expert
2:00remaining
Which option best explains why LangChain uses 'model_kwargs' when connecting to open-source models?

Why does LangChain require passing parameters inside model_kwargs when creating a HuggingFaceHub client?

ABecause LangChain only supports models that require temperature tuning
BBecause the model cannot run without <code>model_kwargs</code> being non-empty
CTo allow flexible configuration of model behavior without changing the client interface
DTo enforce strict typing on all model parameters at runtime
Attempts:
2 left
๐Ÿ’ก Hint

Consider how passing a dictionary of parameters helps with different models.