OPENAI - AZURE SSL error certification verification error

题意:OPENAI - AZURE SSL 错误:证书验证错误

问题背景:

whenever i make a request to azure-openai to create some embeddings the result is the error:

每当我向 Azure-OpenAI 发出创建嵌入的请求时,结果都会出现以下错误:

python 复制代码
Error communicating with OpenAI: HTTPSConnectionPool(host='form-chatgpt-open-ai.openai.azure.com', port=443): Max retries exceeded with url: //openai/deployments/embedding_01/embeddings?api-version=2023-03-15-preview (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)')))

if needed i can provide the code

如果需要,我可以提供代码。

i really don't know how to solve this. i am not behind any vpn, tried to use other wi-fis. has anyone encountered the same problem?

我真的不知道如何解决这个问题。我没有使用任何VPN,也尝试过使用其他Wi-Fi。有没有人遇到过同样的问题?

问题解决:

Codemakers215 answer will not work with openAI > 1.0 anymore. It switched over to use http_client as extra parameter and used httpx under the hood. This gives us more flexibility and not have to change the source anymore.

Codemakers215 的答案在 OpenAI > 1.0 中不再适用了。OpenAI 已经改为使用 http_client 作为额外参数,并在底层使用了 httpx。这给了我们更多的灵活性,不再需要更改源代码。

Also the azure parameters changed a bit.

此外,Azure 的参数也稍微有些变化。

To use it first install 要使用它,首先安装

python 复制代码
pip install httpx[http2]

Option 1: Disable SSL check选项 1:禁用 SSL 检查

python 复制代码
from langchain.schema import AIMessage, HumanMessage
from langchain.chat_models import AzureChatOpenAI

azure_configs ={      
    "azure_endpoint" : "https://<your oai url>.openai.azure.com/",
    "openai_api_version" :"2023-07-01-preview",
    "azure_deployment" : "<your deployment name>",
    "openai_api_key" :"your key",
    "openai_api_type" :"azure",
    "http_client": httpx.Client(verify=False)
}
llm = AzureChatOpenAI(**azure_configs)
result = llm( [HumanMessage(content='Tell me about pluto')])

Option 2: Use custom certs from the CA Store

选项 2:使用来自 CA 存储的自定义证书

When you are behind a firewall or your Company uses custom certs, or you use venv and don't have all the certs in your store, you have to

当你处于防火墙后面,或你的公司使用自定义证书,或者你使用虚拟环境(venv)且存储中没有所有证书时,你需要

  • export the cert from the browser based on your azure url (see solution above)

根据你的 Azure URL 从浏览器导出证书(参考上面的解决方案)

  • attach it to the CA Store (see solution above)

将其附加到 CA 存储中(参考上面的解决方案)

At that point you can check if the default response is working again

此时,你可以检查默认响应是否再次正常工作

python 复制代码
url ="https://platform.openai.com/" # or your azure url
response = requests.get(url)

The issue is still with openai module. The default httpx setting does not uses the requests.certs path. That's where you can just send it through via:

问题仍然出在 OpenAI 模块上。默认的 httpx 设置不使用 requests.certs 路径。你可以通过以下方式直接发送它:

python 复制代码
requests.certs.where()

All together: 总之:

python 复制代码
from langchain.schema import AIMessage, HumanMessage
from langchain.chat_models import AzureChatOpenAI

azure_configs ={      
    "azure_endpoint" : "https://<your oai url>.openai.azure.com/",
    "openai_api_version" :"2023-07-01-preview",
    "azure_deployment" : "<your deployment name>",
    "openai_api_key" :"your key",
    "openai_api_type" :"azure",
    "http_client": httpx.Client(verify=requests.certs.where())
}
llm = AzureChatOpenAI(**azure_configs)
result = llm( [HumanMessage(content='Tell me about pluto')])
相关推荐
寻星探路2 小时前
【前端基础】HTML + CSS + JavaScript 快速入门(三):JS 与 jQuery 实战
java·前端·javascript·css·c++·ai·html
杨浦老苏3 小时前
本地优先的AI个人助手Moltis
人工智能·docker·ai·群晖
阿杰学AI5 小时前
AI核心知识110—大语言模型之 AI Collaboration Manager(简洁且通俗易懂版)
人工智能·ai·语言模型·自然语言处理·aigc·人机交互·ai协作管理员
华农DrLai8 小时前
向量嵌入入门:给每个词分配一个“数字指纹“
大数据·人工智能·ai·llm·rag
爱跑步的程序员~8 小时前
SpringBoot集成SpringAI与Ollama本地大模型
java·后端·spring·ai·llama·springai
冼紫菜8 小时前
Claude整理的Dify平台学习教程资源
后端·学习·ai·llm·agent·dify
x-cmd11 小时前
[特殊字符] 新年新气象|x-cmd v0.8.3:Apache 2.0、Minimax M2.5、Claude Code 一键切换
ai·apache·agent·claude·x-cmd·minimax
万悉科技11 小时前
千问春节1.3亿数据引爆“零点击”消费:品牌如抢占AI流量?
ai·语言模型·流量运营·用户运营·内容运营
Suryxin.12 小时前
从0开始复现nano-vllm「llm_engine.py」
人工智能·python·深度学习·ai·vllm
阿杰学AI12 小时前
AI核心知识109—大语言模型之 Industry Agent Operations Specialist(简洁且通俗易懂版)
大数据·人工智能·ai·语言模型·agent·智能体·行业智能体运营师