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

Allow APIRouter to be made from create_service #33

Open
wants to merge 3 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
16 changes: 16 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it yet but it should be possible to use mount

app = FastAPI()
router = APIRouter()


@app.get("/")
def read_main():
    return {"message": "Hello World from main app"}


lang_app: FastAPI = create_service(
    "api.ex1:chain",
)

app.mount("/subapi", lang_app)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello.
Yes you are right on this.

But in my use case cannot define FastAPI application.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would your use case work with lang_app.router?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it solve your issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not able to have access to app for my use case.
So the only solution is to do my proposal.

## Docs

Automatically served FastAPI doc
Expand Down
4 changes: 2 additions & 2 deletions langcorn/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down