Skip to Main Content

Developer Community

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Importing LangChain into a Python OCI Function failing

Ben NormanJan 27 2025

I'm trying to use LangChain in a Python OCI Function and I'm getting the following error when trying to import anything from LangChain:

"01JJKPZFJS1BT0C20ZJ0011W8X - fn - ERROR - 'NoneType' object is not callable:  
File \"/python/fdk/runner.py\", line 74, in handle_request\\n    response_data = await with_deadline(ctx, handler_code, body)\\n                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  
File \"/python/fdk/runner.py\", line 54, in with_deadline\\n    raise ex\\n  File \"/python/fdk/runner.py\", line 47, in with_deadline\\n    handle_func = handler_code.handler()\\n                  ^^^^^^^^^^^^^^^^^^^^^^\\n  
File \"/python/fdk/customer_code.py\", line 94, in handler\\n    mod = self._delayed_module_class.get_module()\\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  
File \"/python/fdk/customer_code.py\", line 59, in get_module\\n    .load_module()\\n     ^^^^^^^^^^^^^\\n  
File \"<frozen importlib._bootstrap_external>\", line 605, in _check_name_wrapper\\n  File \"<frozen importlib._bootstrap_external>\", line 1121, in load_module\\n  
File \"<frozen importlib._bootstrap_external>\", line 945, in load_module\\n  
File \"<frozen importlib._bootstrap>\", line 290, in _load_module_shim\\n  
File \"<frozen importlib._bootstrap>\", line 721, in _load\\n  
File \"<frozen importlib._bootstrap>\", line 690, in _load_unlocked\\n  
File \"<frozen importlib._bootstrap_external>\", line 940, in exec_module\\n  
File \"<frozen importlib._bootstrap>\", line 241, in _call_with_frames_removed\\n  
File \"/function/func.py\", line 6, in <module>\\n    from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI\\n  
File \"/python/langchain_community/chat_models/oci_generative_ai.py\", line 18, in <module>\\n    from langchain_core.callbacks import CallbackManagerForLLMRun\\n  
File \"/python/langchain_core/callbacks/__init__.py\", line 23, in <module>\\n    from langchain_core.callbacks.manager import (\\n  
File \"/python/langchain_core/callbacks/manager.py\", line 23, in <module>\\n    from langsmith.run_helpers import get_tracing_context\\n  
File \"/python/langsmith/run_helpers.py\", line 56, in <module>\\n    _PARENT_RUN_TREE = contextvars.ContextVar[Optional[run_trees.RunTree]](\\n                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n"

These are the LangChain modules I'm trying to import:

from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI
from langchain_community.utilities import SQLDatabase
from langchain_experimental.sql import SQLDatabaseSequentialChain
from langchain.prompts.prompt import PromptTemplate

I get the error for all of these import statements (have tried each individually, same result) with or without using any of these imports further in my code.

Some context on my environment:

  • The Function is deploying successfully, error only occurs at invocation.
  • Building in Python 3.11
  • My requirements.txt has the following:
fdk>=0.1.86
oci
oracledb
langchain-community==0.3.15
langchain-experimental==0.3.4
langchain==0.3.15
sqlalchemy

I've tried pinning the versions as above and not pinning the versions, same error. I've also successfully run these imports along with the rest of my code locally using the above pinned versions in Python 3.11, and it works perfectly fine.

I've also tried using earlier LangChain versions along with using a Python 3.9 and Python 3.8 OCI Function environment, same issue.

It seems therefore to be a problem running these particular Python imports in the OCI Function environment. Taking out these imports allows my code to work ok.

At a bit of a loss, any ideas or help would be great. Also first time posting to Oracle Forums so apologies if my question format isn't quite right or details are missing, happy to clarify further if needed!

Comments

Post Details

Added on Jan 27 2025
0 comments
200 views