前两天升级openai后,这两天一直在解决下面的错误,openai的error属性缺失
File /usr/local/lib/python3.11/site-packages/langchain/chat_models/openai.py:77, in _create_retry_decorator(llm, run_manager)
68 def _create_retry_decorator(
69 llm: ChatOpenAI,
70 run_manager: Optional[
71 Union[AsyncCallbackManagerForLLMRun, CallbackManagerForLLMRun]
72 ] = None,
73 ) -> Callable[[Any], Any]:
74 import openai
76 errors = [
---> 77 openai.error.Timeout,
78 openai.error.APIError,
79 openai.error.APIConnectionError,
80 openai.error.RateLimitError,
81 openai.error.ServiceUnavailableError,
82 ]
83 return create_base_retry_decorator(
84 error_types=errors, max_retries=llm.max_retries, run_manager=run_manager
85 )
AttributeError: module 'openai' has no attribute 'error'
开始有点着急,毕竟openai已经是最新版本了,不想降级,然后就开始把openai.py里的相关code都注释掉,这下可好,压下葫芦起了瓢,各种稀奇古怪的问题都跑出来,
不得已检查各种包的版本
pip3 list --outdated
发现langchain也要升级了,最后一招制敌。
pip3 install --upgrade langchain
升级到新版本后,问题解决了
pip3 show langchain
Name: langchain
Version: 0.0.352
Summary: Building applications with LLMs through composability
Home-page: https://github.com/langchain-ai/langchain
Author:
Author-email:
License: MIT
Location: /usr/local/lib/python3.11/site-packages
Requires: aiohttp, dataclasses-json, jsonpatch, langchain-community, langchain-core, langsmith, numpy, pydantic, PyYAML, requests, SQLAlchemy, tenacity
如果按照网上的建议,非得降级才能解决,这不是自断手脚嘛。
pip install openai==0.28.1
pip install langchain==0.0.330