Challenge - 5 Problems
LangServe API Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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'
Attempts:
2 left
💡 Hint
Think about what reversing the string 'hello' produces.
✗ Incorrect
The chain reverses the input text, so 'hello' becomes 'olleh'.
📝 Syntax
intermediate2: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
Attempts:
2 left
💡 Hint
Check the parameter name for HTTP methods in add_endpoint.
✗ Incorrect
The correct parameter is 'methods' as a list of HTTP methods.
🔧 Debug
advanced2: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"}
Attempts:
2 left
💡 Hint
Check the expected input key names for ConversationChain.
✗ Incorrect
ConversationChain expects input with key 'input'. Sending 'message' causes a KeyError.
❓ state_output
advanced2: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?
Attempts:
2 left
💡 Hint
Think about how LangServe stores endpoints internally.
✗ Incorrect
LangServe stores endpoints in a dictionary mapping paths to chains.
🧠 Conceptual
expert2: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.
Attempts:
2 left
💡 Hint
Focus on LangServe's function in deployment and API exposure.
✗ Incorrect
LangServe provides a simple server to expose LangChain chains as HTTP endpoints easily.