langchain-ai / langserve

LangServe 🦜️🏓
Other
1.84k stars 203 forks source link

APIRouter(): GET /openai/playground HTTP/1.0" 307 Temporary Redirect #279

Closed lgertel closed 8 months ago

lgertel commented 8 months ago

I'm getting this issue with bigger applications that use APIRouter.

llm_router = APIRouter() add_routes(llm_router, ChatOpenAI(), path="/openai") add_routes(llm_router, GooglePalm(), path="/palm2")

` app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=[""], allow_credentials=True, allow_methods=[""], allow_headers=["*"], )

app.include_router(llm_router)

`

The weird thing is that it works if I add the / after the path on the browser.

eyurtsev commented 8 months ago

Thanks for reporting -- probably a missing / somewhere will take a look!

eyurtsev commented 8 months ago

Hi @lgertel, I hope I'm not missing something deeper here -- the correct URL for the playground is expected to have e trailing /. If you enter a URL without a trailing /, fastapi automatically does a redirect and to a URL that does include a trailing /.

I updated the README in a few places to make sure endpoints have trailing slashes: https://github.com/langchain-ai/langserve/pull/282

I'll close the issue for now, but feel free to re-open if you think I misunderstood it :)

dryprogrammer commented 7 months ago

Does it make sense to enable FastAPI strip_slashes=True rather than asking users to follow the README to the slash?