AI / LangGraph LangChain Interview questions
What is LangServe?
LangServe is a library that turns any LCEL chain into a production-ready REST API in a few lines of code. It wraps FastAPI and exposes standard endpoints — /invoke, /batch, /stream, and /stream_log — so clients can call your chain over HTTP without any custom FastAPI code.
pip install langserve[all] fastapi uvicorn
from fastapi import FastAPI from langserve import add_routes from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser app = FastAPI(title="My LLM API") chain = ( ChatPromptTemplate.from_template("Answer: {question}") | ChatOpenAI() | StrOutputParser() ) add_routes(app, chain, path="/qa") # uvicorn server:app --host 0.0.0.0 --port 8000
Once running, the /qa/invoke endpoint accepts POST with {"input": {"question": "..."}}, /qa/stream returns an SSE stream, and /qa/playground serves an interactive browser UI. LangServe also generates an OpenAPI schema at /docs automatically.
More Related questions...