truera / trulens

Evaluation and Tracking for LLM Experiments
https://www.trulens.org/
MIT License
2.07k stars 181 forks source link

[BUG] OpenAICallbackHandler Issue- LangChainDeprecationWarning #1270

Closed hackrz closed 1 month ago

hackrz commented 3 months ago

Bug Description getting OpenAICallbackHandler error and nltk_data error

To Reproduce Seems to be hidden dependencies in trulens_eval package installation This piece of code in Pycharm 2024.1 community edition from trulens_eval import Feedback, LiteLLM, TruLlama

Expected behavior No error

Relevant Logs/Tracebacks LangChainDeprecationWarning: Importing OpenAICallbackHandler from /Users/abc/PycharmProjects/rag_training/.venv/lib/python3.12/site-packages/langchain/callbacks/openai_info.py is deprecated. Please replace deprecated imports:

from /Users/abc/PycharmProjects/rag_training/.venv/lib/python3.12/site-packages/langchain/callbacks/openai_info.py import OpenAICallbackHandler

with new imports of:

from langchain_community.callbacks.openai_info import OpenAICallbackHandler You can use the langchain cli to automatically upgrade many imports. Please see documentation here https://python.langchain.com/v0.2/docs/versions/v0_2/ warn_deprecated( [nltk_data] Error loading stopwords: <urlopen error [SSL: [nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed: [nltk_data] unable to get local issuer certificate (_ssl.c:1000)> [nltk_data] Error loading punkt: <urlopen error [SSL: [nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed: [nltk_data] unable to get local issuer certificate (_ssl.c:1000)>

Environment:

Additional context The debugging options so far:

  1. used the langchain cli to automatically upgrade any imports. Then cleared the cache in pycharm and restarted it. But no luck
  2. Code line “from langchain_community.callbacks.openai_info import OpenAICallbackHandler” is already reflected in openai_info.py file.

Though the code exits with 0, not sure if it will create any issues down the line

dosubot[bot] commented 3 months ago

Hello, @hackrz! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!

To resolve the OpenAICallbackHandler deprecation warning and the nltk_data certificate verification error, follow these steps:

  1. Deprecation Warning for OpenAICallbackHandler:

    • Update your import statement to use the new path:
      from langchain_community.callbacks.openai_info import OpenAICallbackHandler
    • Ensure that all instances of the old import path are replaced with the new one. You can use the langchain CLI tool to help with this process as described in the LangChain documentation.
  2. NLTK Data Certificate Verification Error:

    • Bypass SSL certificate verification for NLTK by adding the following code at the beginning of your script:

      import ssl
      import nltk
      
      # Bypass SSL certificate verification
      ssl._create_default_https_context = ssl._create_unverified_context
      
      # Download the NLTK data
      nltk.download('stopwords')
      nltk.download('punkt')

By following these steps, you should be able to resolve both the deprecation warning and the certificate verification error [1].

To continue talking to Dosu, mention @dosu.

hackrz commented 3 months ago

I already tried option 1 per my description in issue and option 2 did not work in pycharm

sfc-gh-pmardziel commented 3 months ago

Thanks for the deprecation warning. I think the nltk error was unrelated here. Were you fully online when this happened? I'm guessing that you might have had the nltk download request redirected (to a wifi login page or something similar) hence the ssl failure. Can you verify or check that you are getting the same error while fully online?

hackrz commented 2 months ago

It was on Pycharm and my wifi was also fully functional on macOs. Not sure what you meant by fully online. Could you please clarify?

sfc-gh-pmardziel commented 2 months ago

By fully online I was referring to a situation where sometimes with public wifi hotspots, you first connect in such a way that it looks like you are online but all connections get replaced by a special login page where you are asked to accept some hotspot terms or some such. This is one way in which an SSL would fail to verify a connection.

What was the problem when you tried dosu's second suggestion? (can you try it without the ssl... line?)

sfc-gh-pmardziel commented 2 months ago

Also, does this apply to you: https://stackoverflow.com/questions/41348621/ssl-error-downloading-nltk-data/42890688#42890688 ?

hackrz commented 2 months ago

Yes, this worked like a charm. Thanks Do you also have any visibility into LangChainDeprecationWarning issue?