Open kb-0311 opened 2 months ago
I faced the exact same error. Problem was I was able to run the line:
from langsmith.run_helpers import get_run_tree_context
in python shell, which meant that the langsmith was correctly recognized as a package. Further digging helped me identify the root cause, which was a file named langsmith.py
in my code base. I needed to rename it.
How did I find that out? I ran these commands in python shell:
import langsmith
langsmith.__file__
These commands gave me the local file location when I ran it from my code base directory but the actual package file location when ran outside the code directory. Please try the same in your code base and let me know if you still face this error.
Checked other resources
Example Code
from langchain_community.embeddings import DeterministicFakeEmbedding from langchain_community.vectorstores import Chroma, Milvus from langchain_core.documents import Document from langchain_core.runnables import Runnable, RunnableConfig from langchain_core.runnables.utils import Input, Output from langchain_core.vectorstores import VectorStore from langchain_text_splitters import TextSplitter, RecursiveCharacterTextSplitter
class AddOne(Runnable): def invoke(self , input:Input , config : Optional[RunnableConfig] = None) -> Output: return input+1
class Square(Runnable): def invoke(self , input:Input , config : Optional[RunnableConfig] = None) -> Output: return input**2
class Cube(Runnable): def invoke(self , input:Input , config : Optional[RunnableConfig] = None) -> Output: return input**3
class AddAll(Runnable): def invoke(self , input:dict , config : Optional[RunnableConfig] = None) -> Output: return sum(input.values())
def main_invoke(): chain = (AddOne() | { "square " : Square() , "cube" : Cube() } | AddAll()) print(chain.batch([2 , 10 , 11]))
main_invoke()
Error Message and Stack Trace (if applicable)
Traceback (most recent call last): File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/Users/kb-0311/Desktop/langchain/main.py", line 29, in
main()
File "/Users/kb-0311/Desktop/langchain/main.py", line 26, in main
print(sequence.invoke(2)) # Output will be 9
^^^^^^^^^^^^^^^^^^
File "/Users/kb-0311/Desktop/langchain/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2476, in invoke
callback_manager = get_callback_manager_for_config(config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/kb-0311/Desktop/langchain/.venv/lib/python3.12/site-packages/langchain_core/runnables/config.py", line 433, in get_callback_manager_for_config
from langchain_core.callbacks.manager import CallbackManager
File "/Users/kb-0311/Desktop/langchain/.venv/lib/python3.12/site-packages/langchain_core/callbacks/init.py", line 22, in
from langchain_core.callbacks.manager import (
File "/Users/kb-0311/Desktop/langchain/.venv/lib/python3.12/site-packages/langchain_core/callbacks/manager.py", line 29, in
from langsmith.run_helpers import get_run_tree_context
ModuleNotFoundError: No module named 'langsmith.run_helpers'; 'langsmith' is not a package
Description
I am trying to run a basic example chain to understand lcel but cannot run or invoke my chain.
The error stack trace is given below.
All the packages are installed in a virtual env as well as my global pip lib/ in their latest versions.
System Info
pip freeze | grep langchain langchain==0.2.3 langchain-community==0.2.4 langchain-core==0.2.5 langchain-text-splitters==0.2.1 MacOS 14.5 Python3 version 3.12.3