baidubce / bce-qianfan-sdk

Provide best practices for LMOps, as well as elegant and convenient access to the features of the Qianfan MaaS Platform. (提供大模型工具链最佳实践,以及优雅且便捷地访问千帆大模型平台)
https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html
Apache License 2.0
265 stars 39 forks source link

使用 langchain QianfanChatEndpoint 不能连接服务器,SSL #632

Open asynchat opened 3 days ago

asynchat commented 3 days ago

System Info

python 3.11, qianfan = "^0.3.18"

Reproduction

[INFO][2024-07-01 20:46:04.483] oauth.py:252 [t:8502742016]: trying to refresh access_token for akqXoGNC [ERROR][2024-07-01 20:46:05.535] oauth.py:265 [t:8502742016]: refresh access token failed with exception Cannot connect to host aip.baidubce.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] [WARNING][2024-07-01 20:46:05.536] oauth.py:134 [t:8502742016]: access token is not available for akqXoGNC [INFO][2024-07-01 20:46:05.536] oauth.py:252 [t:8502742016]: trying to refresh access_token for akqXoGNC [ERROR][2024-07-01 20:46:05.765] oauth.py:265 [t:8502742016]: refresh access token failed with exception Cannot connect to host aip.baidubce.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')] Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x13d09e9d0> [WARNING][2024-07-01 20:46:05.768] oauth.py:134 [t:8502742016]: access token is not available for akqXoGNC Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x13cf70c10>

asynchat commented 3 days ago

langchain-core = "^0.2.10" langchain-community = "^0.2.6"

danielhjz commented 3 days ago

以下是可能的一些解决方案:

  1. 可以尝试使用iam access_key和secret鉴权(无需获取access_token): 可以从登录智能云从此处获取
    
    import os
    from langchain_community.chat_models import QianfanChatEndpoint
    from langchain_core.language_models.chat_models import HumanMessage

os.environ["QIANFAN_ACCESS_KEY"] = "your_access_key" os.environ["QIANFAN_SECRET_KEY"] = "your_secret_key"

chat = QianfanChatEndpoint(streaming=True) messages = [HumanMessage(content="Hello")] resp = chat.invoke(messages)


2. 不检验证书(可能存在中间人攻击等安全风险):
```python
import os
os.environ["QIANFAN_SSL_VERIFICATION_ENABLED"]="False"