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

Unable to open playground page when using add_routes() with FastAPI's APIRouter #578

Open
StreetLamb opened this issue Mar 30, 2024 · 5 comments
Assignees

Comments

@StreetLamb
Copy link

I'm using APIRouter to separate my routes like so:

# app/main.py
app.include_router(api_router, prefix='/api/v1')

# app/api/main.py
from app.api.routes import chat

api_router = APIRouter()
api_router.include_router(chat.router, prefix="/chat", tags=["chats"])

# app/api/routes/chat.py
router = APIRouter()
add_routes(
    router,
    ChatOpenAI(),
)

I am able to access http://localhost /api/v1/chat/invoke properly. However http://localhost/api/v1/chat/playground brings me to a blank page. I get the error: Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.

On inspecting network, issue seems to be that the page is incorrectly fetching the playground assets from the base URL http://localhost/playground/assets/index-dbc96538.js instead of http://localhost/api/v1/chat/playground/assets/index-dbc96538.js.

My workaround for now is to move all the prefixes into add_routes instead:

# app/main.py
app.include_router(api_router)

# app/api/main.py
from app.api.routes import chat

api_router = APIRouter()
api_router.include_router(chat.router, tags=["chats"])

# app/api/routes/chat.py
router = APIRouter()
add_routes(
    router,
    ChatOpenAI(),
    path="/api/v1/chat"
)

Ideally, it should be able to infer the correct path when working with prefixes.

@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 30, 2024

Thanks! Will take a look on Monday. Which version of langserve are you on?

@StreetLamb
Copy link
Author

Thanks for looking into it! I'm using 0.0.51

@eyurtsev
Copy link
Collaborator

@StreetLamb I am unable to reproduce, would you be kind enough to help me create an MRE with the unit tests?

https://github.com/langchain-ai/langserve/pull/579/files#diff-0796d94e9487fc7c014344ad4a1150ba02c980991a7433ad811f3fef23d843dfR63

@StreetLamb
Copy link
Author

Hi @eyurtsev, raised a PR to update the playground unit tests as requested.

@SwenRanj
Copy link

SwenRanj commented May 14, 2024

Hi, I am having the same issue on langserve version 0.1.1.
I noticed that the playground works when you supply a path to the add_routes function, but not when you use the prefix in include_router (like the sample that @StreetLamb provided.

Any news on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants