You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After setting logging in httpx to debug, I discovered that the final client used by the langchain abstraction is a new one, probably created along the way. The client parameter passed down is lost along the way somewhere.
Result from langchain client
The model parameter is wrong (supposed to be deployment_name) and also the host its connecting to is the base url instead of my proxy url.
INFO [2024-05-1409:18:23] openai._base_client-Retryingrequestto/chat/completionsin0.873755secondsDEBUG [2024-05-1409:18:24] openai._base_client-Requestoptions: {'method': 'post', 'url': '/chat/completions', 'headers': {'api-key': API_KEY, 'files': None, 'json_data': {'messages': [{'role': 'user', 'content': 'test'}], 'model': 'gpt-3.5-turbo', 'n': 1, 'stream': False, 'temperature': 0.0}}
DEBUG [2024-05-1409:18:24] httpcore.connection-connect_tcp.startedhost='BASE_URL'port=443local_address=Nonetimeout=Nonesocket_options=NoneDEBUG [2024-05-1409:18:24] httpcore.connection-connect_tcp.failedexception=ConnectError(gaierror(-2, 'Name or service not known'))
Result from openai client (correct)
Observe the differences in the model and host parameters. they are correctly set to deployment_name and the proxy url.
Honestly I have no idea. Theres too many magic abstractions going on here. The client parameter is being ignored somewhere down the line.
I poked into AzureChatOpenAI and saw validate_environment but I dont see it being called anywhere.
Digging into BaseChatOpenAI and BaseChatModel didnt do much good either.
How I fixed this on my end was a major hack - replacing the final client used with my httpx client after initialiation.
fromlangchain_openaiimportAzureChatOpenAIimporthttpxbase_url="url"client=httpx.Client(proxy="proxy",verify=False, follow_redirects=True)
model=AzureChatOpenAI(base_url=base_url,openai_api_version=OPENAI_API_VERSION, openai_api_key=OPENAI_API_KEY, temperature=0,client=client)
model.client._client._client=client# replace the SyncHttpxClientWrapper client with own httpx instancemodel.invoke("this works")
The text was updated successfully, but these errors were encountered:
dosubotbot
added
🔌: openai
Primarily related to OpenAI integrations
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
labels
May 14, 2024
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
Description
The openai python library provides a
client
parameter that allows you to configure proxy settings, and disable ssl verification.The langchain abstraction ignores this, and sets a default client, resulting in it not working.
For example, this is the openai equivalent which works
Why?
After setting logging in
httpx
to debug, I discovered that the final client used by the langchain abstraction is a new one, probably created along the way. The client parameter passed down is lost along the way somewhere.Result from langchain client
The model parameter is wrong (supposed to be deployment_name) and also the host its connecting to is the base url instead of my proxy url.
Result from openai client (correct)
Observe the differences in the model and host parameters. they are correctly set to deployment_name and the proxy url.
How to fix?
Honestly I have no idea. Theres too many magic abstractions going on here. The client parameter is being ignored somewhere down the line.
I poked into
AzureChatOpenAI
and sawvalidate_environment
but I dont see it being called anywhere.Digging into
BaseChatOpenAI
andBaseChatModel
didnt do much good either.How I fixed this on my end was a major hack - replacing the final client used with my httpx client after initialiation.
System Info
langchain==0.1.12
langchain-community==0.0.28
langchain-core==0.1.52
langchain-experimental==0.0.40
langchain-openai==0.1.6
langchain-text-splitters==0.0.1
langchainhub==0.1.15
windows on wsl
python3.10
The text was updated successfully, but these errors were encountered: