langserve
langserve copied to clipboard
Renaming components in the `packages/` directory breaks component imports
Attemping to rename a package which has been added via langchain cli breaks langchain serve. This issue appears to affect all LangChain apps currently.
Expected Behavior
If a package component is renamed properly in all locations, LangServe should respect the renamed package and import it correctly.
Current Behavior
Renaming a langchain / langserve app component results in broken imports.
Possible Solution
Some extra step (which appears to be undocumented afaik) must be performed to update the package component so LangChain has visibility of it.
Steps to Reproduce
- Create a LangChain app with a package, e.g.:
langchain app new my-app --package rag-conversation. - Rename the component in the
packages/directory, e.g.:rag-conversation->rag(be sure to also updatepyproject.tomlnameandexport_module, andapp/server.pychain import. - Run
langchain serve. - Get following error:
from rag import chain as rag_conversation_chain
ModuleNotFoundError: No module named 'rag'
Hey @Cutwell ! This isn't currently-supported behavior. If you want to switch out the path, there are a few more things to note!
All packages are installed as editable "path" dependencies, so you'll have to re-install the new package (you may want to remove the old one before renaming too).
The from x import chain x is going to be the inner folder within the package (same as all python packages), so you'll need to make sure your x is equal the python path within the inner folder.
app/
packages/
rag/
pyproject.toml
**x/**
__init__.py
chain.py
The other option you have is to langchain app add rag-conversation --api-path=rag to "add" the package at a custom path.
Let me know how else I can help!
Hi @efriis , thanks for your response.
I think we can achieve the desired result with existing functionality and some manual steps..
- Copy the package component to elsewhere in my repository
- Remove the langserve component with
langchain app remove my-app - Rename the copied component appropriately
- Re-add the component from a local sourcepath (
langchain app add ...?) - Tidy up the copied component and resume development with the newly created / renamed package component
This works up until step 4 - I can create a new LangServe app using a local component as a package using langchain app new my-langserve --package $PWD/my-app, but it's unclear how to do this with an existing langserve project.
How can I export multiple modules and attr under tool.langserve ?