-
Notifications
You must be signed in to change notification settings - Fork 214
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
Failure to import langserve because fastapi is missing #212
Comments
Hi @cbornet thanks for reporting! This behavior is intentional -- Langserve contains both server and client code, and the client code should be installable without fastapi as a requirement. Use the 'all' extra to install both client and server dependencies. |
Currently
It is because both the server and client code are imported in the root |
Yeah :( It's a bug -- tests aren't set up to catch that yet, once the tests are set up should be much easier hopefully |
Is there any work on this? This issue currently has a Like @cbornet mentioned, both the client and the server are imported in the root I believe this leaves three solutions:
|
I came across this because I want to use When I try to import it, I get this error. I'd prefer not to install |
Honestely? Just patch it yourself, it doesn't seem like they're ever going to patch this dumb design flaw. If you have control over the installations, any of the three options could work. Otherwise, you could do some very dirty import patching like this: import sys
class fakemodule(object):
@classmethod
def __getattribute__(cls, name: str):
return cls
sys.modules["fastapi"] = fakemodule()
sys.modules["fastapi.encoders"] = fakemodule()
sys.modules["fastapi.exceptions"] = fakemodule()
sys.modules["starlette"] = fakemodule()
sys.modules["starlette.requests"] = fakemodule()
sys.modules["starlette.responses"] = fakemodule()
sys.modules["fastapi.responses"] = fakemodule()
from langserve import RemoteRunnable |
Just a quickfix for #212. It would be better not to have to install fastapi only for using the client, but in my opinion this is still better then getting errors when importing the `RemoteRunnable` after a `pip install "langserve[client]"`. Otherwise at least the readme should be updated. --------- Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
@eyurtsev any update on this? |
Hi @Vinno97, I won't get to this soon, but I'm happy to review any PRs that fix this issue and happy to provide guidance on how to implement it. |
Sure, I wouldn't mind taking this up. However, my prefered solution (the first option from my previous message), would require an API-breaking change. Its effect would be fairly minimal as people would just need to change out their imports for more specific ones, though it's still breaking: from langserve import RemoteRunnable -> from langserve.client import RemoteRunnable
from langserve import add_routes, APIHandler -> from langserve.server import add_routes, APIHandler For reference, my previous suggestions:
I am not aware of any method to detect the importing of a specific method. If that would be possible, we could print a deprecation notice for a version or two when people still use the |
LangServe declares fastapi as optional dependency but fastapi seems required.
In a new virtual env:
I can fix with a PR if needed.
The text was updated successfully, but these errors were encountered: