langserve icon indicating copy to clipboard operation
langserve copied to clipboard

Renaming components in the `packages/` directory breaks component imports

Open Cutwell opened this issue 2 years ago • 3 comments

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

  1. Create a LangChain app with a package, e.g.: langchain app new my-app --package rag-conversation.
  2. Rename the component in the packages/ directory, e.g.: rag-conversation -> rag (be sure to also update pyproject.toml name and export_module, and app/server.py chain import.
  3. Run langchain serve.
  4. Get following error:
from rag import chain as rag_conversation_chain
ModuleNotFoundError: No module named 'rag'

Cutwell avatar Nov 11 '23 16:11 Cutwell

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!

efriis avatar Nov 13 '23 02:11 efriis

Hi @efriis , thanks for your response.

I think we can achieve the desired result with existing functionality and some manual steps..

  1. Copy the package component to elsewhere in my repository
  2. Remove the langserve component with langchain app remove my-app
  3. Rename the copied component appropriately
  4. Re-add the component from a local sourcepath (langchain app add ...?)
  5. 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.

Cutwell avatar Nov 13 '23 10:11 Cutwell

How can I export multiple modules and attr under tool.langserve ?

sathyarr avatar Oct 22 '24 11:10 sathyarr