Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add langserve #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
server:
poetry run uvicorn plate_chain.server:app --reload

notebook:
jupyter notebook
55 changes: 55 additions & 0 deletions plate_chain/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
"""PlateChain server exposes a chain to parse microplate data."""
from fastapi import FastAPI, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware

from langchain.pydantic_v1 import BaseModel

from langserve import add_routes
from .chain import chain


app = FastAPI(
title="PlateChain Server",
version="0.1",
description="Spin up a simple api server to parse plate data",
)

# Set all CORS enabled origins
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["*"],
)


# The input type is automatically inferred from the runnable
# interface; however, if you want to override it, you can do so
# by passing in the input_type argument to add_routes.
class ChainInput(BaseModel):
"""The input to the chain."""

input: UploadFile = File(...)
num_plates: int | None = None
num_rows: int | None = None
num_cols: int | None = None


@app.post("/upload")
async def upload(args: ChainInput, f: UploadFile = File(...)):
pass


add_routes(app, chain, input_type=UploadFile, config_keys=["configurable"])

# Alternatively, you can rely on langchain's type inference
# to infer the input type from the runnable interface.
# add_routes(app, chain)

if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="127.0.0.1", port=8002, log_level="info")
Loading