0
0
LangChainframework~20 mins

LangServe for API deployment in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LangServe API 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 LangServe API call?
Consider a LangServe API deployed with a simple chain that returns the input text reversed. What will be the response when sending the input 'hello'?
LangChain
from langchain.chains import LLMChain
from langchain.llms import OpenAI
from langchain.server import LangServe

llm = OpenAI(temperature=0)
chain = LLMChain(llm=llm, prompt_template="{input_text[::-1]}")
app = LangServe()
app.add_endpoint("/reverse", chain)

# Simulate API call with input_text='hello'
A"hello"
B"olleh"
C"HELLO"
D"error"
Attempts:
2 left
💡 Hint
Think about what reversing the string 'hello' produces.
📝 Syntax
intermediate
2:00remaining
Which option correctly adds a POST endpoint in LangServe?
You want to add a POST endpoint '/summarize' to your LangServe app that uses a chain named 'summary_chain'. Which code snippet is correct?
LangChain
from langchain.server import LangServe
app = LangServe()

# summary_chain is defined elsewhere
Aapp.add_endpoint('/summarize', summary_chain, verbs=['POST'])
Bapp.add_endpoint('/summarize', summary_chain, method='POST')
Capp.add_endpoint('/summarize', summary_chain, methods=['POST'])
Dapp.add_endpoint('/summarize', summary_chain, http_methods=['POST'])
Attempts:
2 left
💡 Hint
Check the parameter name for HTTP methods in add_endpoint.
🔧 Debug
advanced
2:00remaining
Why does this LangServe app raise a runtime error?
Given this code snippet, why does the LangServe app fail when calling the '/chat' endpoint? from langchain.chains import ConversationChain from langchain.llms import OpenAI from langchain.server import LangServe llm = OpenAI() chain = ConversationChain(llm=llm) app = LangServe() app.add_endpoint('/chat', chain) # The client sends JSON: {"message": "Hello"}
AThe chain expects input key 'input' but client sends 'message', causing a KeyError.
BThe OpenAI LLM is not initialized with temperature=0 causing instability.
CLangServe requires endpoints to be async functions, but chain is sync.
DThe ConversationChain does not support JSON input format.
Attempts:
2 left
💡 Hint
Check the expected input key names for ConversationChain.
state_output
advanced
2:00remaining
What is the state of the LangServe app after adding two endpoints?
You add two chains as endpoints: app.add_endpoint('/translate', translate_chain) app.add_endpoint('/summarize', summarize_chain) What does app.endpoints contain?
AA set containing the endpoint paths only.
BA list containing the two chain objects in order added.
CAn empty dictionary because endpoints are not stored.
DA dictionary with keys '/translate' and '/summarize' mapping to their respective chains.
Attempts:
2 left
💡 Hint
Think about how LangServe stores endpoints internally.
🧠 Conceptual
expert
2:00remaining
Which statement best describes LangServe's role in API deployment?
Select the most accurate description of what LangServe provides for deploying LangChain chains as APIs.
ALangServe acts as a lightweight server framework that exposes LangChain chains as HTTP endpoints with minimal setup.
BLangServe is a cloud service that automatically scales LangChain chains without any local setup.
CLangServe is a GUI tool for designing LangChain chains visually before deployment.
DLangServe replaces LangChain's LLMs with custom models optimized for API use.
Attempts:
2 left
💡 Hint
Focus on LangServe's function in deployment and API exposure.