From 7a84c95d5be2eee810212b34e1016ac5592cceed Mon Sep 17 00:00:00 2001 From: Thomas PEDOT Date: Thu, 24 Aug 2023 17:08:44 +0200 Subject: [PATCH 1/2] Allow APIRouter to be made from create_service There is no problem to use APIRouter instead of FastAPI --- langcorn/server/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/langcorn/server/api.py b/langcorn/server/api.py index 883a85d..b131292 100644 --- a/langcorn/server/api.py +++ b/langcorn/server/api.py @@ -2,7 +2,7 @@ import sys from typing import Any, Union -from fastapi import Depends, FastAPI, Header, HTTPException, Request +from fastapi import APIRouter, Depends, FastAPI, Header, HTTPException, Request from fastapi.security.utils import get_authorization_scheme_param from langchain.schema import messages_from_dict, messages_to_dict from loguru import logger @@ -122,7 +122,7 @@ async def handler(request: request_cls, http_request: Request): return handler -def create_service(*lc_apps, auth_token: str = "", app: FastAPI = None): +def create_service(*lc_apps, auth_token: str = "", app: FastAPI or APIRouter = None): # Make local modules discoverable sys.path.append(os.path.dirname(".")) logger.info("Creating service") From 1a283093959f1e07a081f9d8264410c1e6b4510a Mon Sep 17 00:00:00 2001 From: Thomas PEDOT Date: Thu, 24 Aug 2023 17:12:16 +0200 Subject: [PATCH 2/2] Update Readme.md --- Readme.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Readme.md b/Readme.md index 0b269aa..4b02dcf 100644 --- a/Readme.md +++ b/Readme.md @@ -136,6 +136,22 @@ uvicorn main:app --host 0.0.0.0 --port 8000 Now, your LangChain models and pipelines are accessible via the LangCorn API server. +With a router : +```python +app = FastAPI() +router = APIRouter() + + +@app.get("/") +def read_main(): + return {"message": "Hello World from main app"} + +router: APIRouter = create_service(router, + "api.ex1:chain", +) +app.include_router(router) +``` + ## Docs Automatically served FastAPI doc