langchain-ai / langchain-nvidia

MIT License
48 stars 15 forks source link

SSL Validation Error with NVIDIAChat API Call to Local NIM #76

Closed conaku closed 1 month ago

conaku commented 1 month ago

Sample Code import os from langchain_nvidia_ai_endpoints import ChatNVIDIA

os.environ["NVIDIA_API_KEY"] = "nvapi-*****"

os.environ["REQUESTS_CA_BUNDLE"] = '/usr/local/share/ca-certificates/test.crt'

os.environ["SSL_CERT_FILE"] = '/usr/local/share/ca-certificates/test.crt'

This one works with NVIDIA_API_KEY

llm = ChatNVIDIA(model="mistralai/mixtral-8x7b-instruct-v0.1")

This one does not work with local NIM

llm = ChatNVIDIA(base_url="https://ashish-mistral-nim-deploy-1-predictor.******/v1/completions", model="mistralai/mistral-7b-instruct-v0.3") result = llm.invoke("Tell me something about langchain.")

Error requests.exceptions.SSLError: HTTPSConnectionPool(host='ashish-mistral-nim-deploy-1-predictor.mlis.ezua.hp.com', port=443): Max retries exceeded with url: /v1/completions/chat/completions (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')))

conaku commented 1 month ago

following code works fine though. (venv39) root@nvrag-01:/stage/ashish# curl --cacert test.crt -X 'POST' 'https://ashish-mistral-nim-deploy-1-predictor.********/v1/completions' -H 'accept: application/json' -H 'Content-Type: application/json' -d '{"model": "mistralai/mistral-7b-instruct-v0.3","prompt": "Tell me something about langchain.","max_tokens": 64}' {"id":"cmpl-8692c2a87308405598bfeb889f0b0e74","object":"text_completion","created":1721741519,"model":"mistralai/mistral-7b-instruct-v0.3","choices":[{"index":0,"text":"\n\nLangchain is an open-source artificial intelligence (AI) project that focuses on creating a decentralized, community-driven translation and language learning platform. The project uses blockchain technology and smart contracts to create a system where translation, language learning, and content creation are incentivized through a token-based","logprobs":null,"finish_reason":"length","stop_reason":null}],"usage":{"prompt_tokens":8,"total_tokens":72,"completion_tokens":64}}(venv39) root@nvrag-01:/stage/ashish#

conaku commented 1 month ago

Am closing this issue. NVIDIAChat API is working fine after creating the chain of certificate and providing to API call like this

os.environ['SSL_CERT_FILE']='/usr/local/share/ca-certificates/chain.pem'

llm = ChatNVIDIA( base_url="https://ashish-mistral-nim-deploy-1-predictor.************/v1", model="mistralai/mistral-7b-instruct-v0.3", verify="/usr/local/share/ca-certificates/chain.pem" )