-
Notifications
You must be signed in to change notification settings - Fork 16.7k
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
Importing LangChain into a Python OCI Function failing #29468
Comments
Please change your import to: from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI
from langchain_community.utilities import SQLDatabase
from langchain_experimental.sql import SQLDatabaseSequentialChain
from langchain_core.prompts import PromptTemplate
`` |
Thanks for your response. Have corrected the import, have received the same error on function invocation. |
I dug into this because I had the same error, and it seems that the issue might be a compatibility problem among Docker, fdk, and LangChain rather than an issue with LangChain itself. I worked around the problem by using a venv inside the Docker image for an extra layer of isolation. I didn't use the Cloud Shell because this Dockerfile only worked when I built it locally and then pushed (error code at the bottom). FROM fnproject/python:3.11 as build-stage
WORKDIR /function
COPY requirements.txt .
RUN python3 -m venv venv && \
venv/bin/pip install --upgrade pip && \
venv/bin/pip install --no-cache-dir -r requirements.txt && \
rm -rf ~/.cache/pip /tmp*
COPY . .
FROM fnproject/python:3.11
WORKDIR /function
COPY --from=build-stage /function/venv venv
COPY --from=build-stage /function .
ENV PYTHONPATH=/function
ENV PATH="/function/venv/bin:$PATH"
RUN venv/bin/python -c "from langchain_community.chat_models.oci_generative_ai import ChatOCIGenAI"
ENTRYPOINT ["/function/venv/bin/fdk", "/function/func.py", "handler"] I then uploaded the image to OCI Container Registry with This might be not the right place to post, but FYI, the following code is the error that i encountered when i
|
That's worked for me, thank you! I'm also deploying locally so not sure about that cloud editor error, though I have had to downgrade Pydantic to 2.9.2 previously due to other issues with it so perhaps that's part of it. Have you tried to actually call ChatOCIGenAI() yet? Having trouble authenticating both using api key and resource principal. |
Glad to hear it worked! The Dockerfile error went away when i changed my oci environment, so langchain might not be the main reason for the error.
The genai is working beautifully here. Check the documentation once again, and if still persists, we can discuss this in another issue thread :) |
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
"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 "", line 605, in _check_name_wrapper\n File "", line 1121, in load_module\n
File "", line 945, in load_module\n
File "", line 290, in _load_module_shim\n
File "", line 721, in _load\n
File "", line 690, in _load_unlocked\n
File "", line 940, in exec_module\n
File "", line 241, in _call_with_frames_removed\n
File "/function/func.py", line 6, in \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 \n from langchain_core.callbacks import CallbackManagerForLLMRun\n
File "/python/langchain_core/callbacks/init.py", line 23, in \n from langchain_core.callbacks.manager import (\n
File "/python/langchain_core/callbacks/manager.py", line 23, in \n from langsmith.run_helpers import get_tracing_context\n
File "/python/langsmith/run_helpers.py", line 56, in \n _PARENT_RUN_TREE = contextvars.ContextVar[Optional[run_trees.RunTree]](\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"
Description
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.
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.
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
The text was updated successfully, but these errors were encountered: