mirror of
https://github.com/kennethreitz/langchain.git
synced 2026-06-05 23:00:18 +00:00
b05bb9e136
Adds LangServe package * Integrate Runnables with Fast API creating Server and a RemoteRunnable client * Support multiple runnables for a given server * Support sync/async/batch/abatch/stream/astream/astream_log on the client side (using async implementations on server) * Adds validation using annotations (relying on pydantic under the hood) -- this still has some rough edges -- e.g., open api docs do NOT generate correctly at the moment * Uses pydantic v1 namespace Known issues: type translation code doesn't handle a lot of types (e.g., TypedDicts) --------- Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
29 lines
752 B
Python
Executable File
29 lines
752 B
Python
Executable File
#!/usr/bin/env python
|
|
"""Example LangChain server exposes a retrieval."""
|
|
from fastapi import FastAPI
|
|
from langchain.embeddings import OpenAIEmbeddings
|
|
from langchain.vectorstores import FAISS
|
|
|
|
from langserve import add_routes
|
|
|
|
vectorstore = FAISS.from_texts(
|
|
["cats like fish", "dogs like sticks"], embedding=OpenAIEmbeddings()
|
|
)
|
|
retriever = vectorstore.as_retriever()
|
|
|
|
app = FastAPI(
|
|
title="LangChain Server",
|
|
version="1.0",
|
|
description="Spin up a simple api server using Langchain's Runnable interfaces",
|
|
)
|
|
# Adds routes to the app for using the retriever under:
|
|
# /invoke
|
|
# /batch
|
|
# /stream
|
|
add_routes(app, retriever, input_type=str)
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(app, host="localhost", port=8000)
|