OpenAI call does not execute for the first time when used in a script

Hello every one, I have used below mentioned code in one of my script:

OpenAI(temperature=0.1, model_name=“gpt-3.5-turbo-16k”, openai_api_key=openai_api_key, request_timeout=80, max_retries=4)

Now when I am executing the script after a gap of around 4-5 hrs, then my automation script getting failed with below mentioned error message:

“Anaconda_sft\lib\site-packages\langchain\llms\openai.py”:202: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: from langchain.chat_models import ChatOpenAI

  • warnings.warn(*
  • Detected change in ‘Anaconda_sft\Lib\site-packages\langchain\llms\openai.py’, reloading

Anaconda_sft\lib\site-packages\langchain\llms\openai.py:790: UserWarning: You are trying to use a chat model. This way of initializing it is no longer supported. Instead, please use: from langchain.chat_models import ChatOpenAI

  • warnings.warn(*

Can anyone help me in solving this First time execution error which does not call the LLM OPENAI model, however, from the next time onwards it start executing successfully.

Am I missing anything?

What success did you have at following the exact instructions in the error message, to change the method?

OpenAI significantly changed its Python library in November, along with adding new methods and models. That means ensuring that you have a bleeding-edge new version of Langchain, along with libraries:

pip install --update openai tiktoken langchain

or similar for Anaconda.

Then use new methods and invoke.

https://www.datasciencebyexample.com/2023/12/06/calling-openai-chatmodel-using-langchain/