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

Templates on templates.langchain.com don't work with the provided instructions #26734

Open
5 tasks done
dividor opened this issue Sep 20, 2024 · 5 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate

Comments

@dividor
Copy link

dividor commented Sep 20, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

  1. Go to https://templates.langchain.com/
  2. Find Rag Fusion template
  3. Following exactly the instructions there ...
pip install -U langchain-cli
langchain app new my-app --package rag-fusion
cd my-app
langchain serve

I get the error below. I tried 3 different templates, same error.

Error Message and Stack Trace (if applicable)

INFO:     Will watch for changes in these directories: ['/Users/matthewharris/Desktop/git/langchain-templates/rag-fusion']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [11557] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/uvicorn/config.py", line 467, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/matthewharris/Desktop/git/langchain-templates/rag-fusion/app/server.py", line 14, in <module>
    add_routes(app, NotImplemented)
  File "/Users/matthewharris/miniconda3/envs/wfp/lib/python3.11/site-packages/langserve/server.py", line 392, in add_routes
    raise TypeError(
TypeError: Expected a Runnable, got <class 'NotImplementedType'>. The second argument to add_routes should be a Runnable instance.add_route(app, runnable, ...) is the correct usage.Please make sure that you are using a runnable which is an instance of langchain_core.runnables.Runnable.

Description

I am trying to run any of the langchain templates on https://templates.langchain.com/

System Info

python -m langchain_core.sys_info

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 20.6.0: Thu Jul  6 22:12:47 PDT 2023; root:xnu-7195.141.49.702.12~1/RELEASE_X86_64
> Python Version:  3.11.4 (main, Jul  5 2023, 08:41:25) [Clang 14.0.6 ]

Package Information
-------------------
> langchain_core: 0.1.52
> langchain: 0.1.20
> langchain_community: 0.0.38
> langsmith: 0.1.125
> langchain_cli: 0.0.31
> langchain_text_splitters: 0.0.2
> langchainhub: 0.1.21
> langserve: 0.3.0

Packages not installed (Not Necessarily a Problem)
--------------------------------------------------
The following packages were not found:

> langgraph
@langcarl langcarl bot added the investigate label Sep 20, 2024
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Sep 20, 2024
@eyurtsev
Copy link
Collaborator

TypeError: Expected a Runnable, got <class 'NotImplementedType'>. The second argument to add_routes should be a Runnable instance.add_route(app, runnable, ...) is the correct usage.Please make sure that you are using a runnable which is an instance of langchain_core.runnables.Runnable.

I suspect you haven't fully followed the directions. There's a manual step to put the appropriate runnable as an argument to add_routes.

@dividor
Copy link
Author

dividor commented Sep 21, 2024

I am following exactly the directions on the LangChain website ...

https://templates.langchain.com

I am familiar with coding my own LECL chains with no issues, it's the LangChain CLI commands on the web page that don't seem to work. I have tried in a vanilla virtual environment, as they are written, they give the error. I tried a few templates, same thing.

Could you perhaps try following the instructions on the site for rag fusion?

@dividor
Copy link
Author

dividor commented Sep 21, 2024

"There's a manual step to put the appropriate runnable as an argument to add_routes."

That is only to add to an existing app, if I read it correctly ...

image

I am following the "To create a new ..." part, and running that.

@dividor
Copy link
Author

dividor commented Sep 21, 2024

OK, I see the issue.

https://templates.langchain.com/ instructions have this ...

langchain app new my-app --package rag-fusion

Which creates a full app folder and server.py. However, it does not automatically add the route, which being a CLI I thought it would.

The second issue is the wording of the instructions, because it has ...

"If you want to add this to an existing project, you can just run:

langchain app add rag-fusion

And add the following code to your server.py file"

Which reads like you only need to edit the file if editing an existing app.

So my points would be:

  1. If using Langchain CLI to create a new app which uses the template, why not add the route automatically? Everything else is wonderfully automated as part of the CLI
  2. If leaving it as it is, clarify the instructions to mention, you need to edit server.py even if you just used the CLI to create it

@dividor
Copy link
Author

dividor commented Sep 21, 2024

Even after fixing the above the template still fails on langchain serve.

https://templates.langchain.com/ is such a lovely idea, but none of the examples there actually work and the documentation is poor (ambiguous instructions, missing environment variables need to be set, eg PINECONE_API_KEY).

I tried simpler templates, eg rag-chroma, still lots of dependency errors in a vanilla envrionment.

Basically https://templates.langchain.com/ seems pretty much unusable. Has anybody else managed to get a template to work recently?

INFO:     Will watch for changes in these directories: ['/Users/matthewharris/Desktop/git/langchain-templates/rag-fusion']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [29027] using WatchFiles
Process SpawnProcess-1:
Traceback (most recent call last):
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/uvicorn/_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "/Users/matthe/miniconda3/envs/lc/lib/python3.11/site-packages/uvicorn/server.py", line 61, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthe/miniconda3/envs/lc/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/matthewharris/miniconda3/envs/lc/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "uvloop/loop.pyx", line 1517, in uvloop.loop.Loop.run_until_complete
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/uvicorn/server.py", line 68, in serve
    config.load()
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/uvicorn/config.py", line 467, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/uvicorn/importer.py", line 21, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/matthew/Desktop/git/langchain-templates/rag-fusion/app/server.py", line 13, in <module>
    from rag_fusion.chain import chain as rag_fusion_chain
  File "/Users/matthew/Desktop/git/langchain-templates/rag-fusion/packages/rag-fusion/rag_fusion/chain.py", line 7, in <module>
    from langchain_pinecone import PineconeVectorStore
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/langchain_pinecone/__init__.py", line 1, in <module>
    from langchain_pinecone.embeddings import PineconeEmbeddings
  File "/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/langchain_pinecone/embeddings.py", line 6, in <module>
    from langchain_core.utils import secret_from_env
ImportError: cannot import name 'secret_from_env' from 'langchain_core.utils' (/Users/matthew/miniconda3/envs/lc/lib/python3.11/site-packages/langchain_core/utils/__init__.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature investigate
Projects
None yet
Development

No branches or pull requests

2 participants