Open xmduhan opened 2 months ago
Hi @xmduhan. Thank you for opening this PR. Could you help me understand the use case here? Could you instead use the base_url
client parameter to specify a proxy?
Of course, you can specify the required proxy settings in the code, but this means that the code needs to be adjusted differently under different execution environments. As for the better solution, try not to modify my code, but set different execution variables in different execution environments. For example, there are two machines A and B. A can access the Internet without using a proxy, but B must access the proxy. Without modifying the code, we only need to set B's environment variables http_proxy and https_proxy to make the programs on both machines run successfully. This is also a requirement of the 12-factor principle. 12factor
@xmduhan Thanks for clarifying.
I'm inclined to minimize the API surface area of the client itself, delegating additional behavior to httpx. Reading through the docs, I'm surprised that httpx didn't automatically pick up those environment variables.
You can accomplish this currently without changing the client by passing httpx.HTTPTransport(proxy=proxy)
as a transport
parameter to the Client
constructor. We can certainly do more to make the Replicate client more composable with httpx and document that better, and I'd love to invest some time into that.
This may indeed be a problem with http. By default, it can automatically read http_proxy, but when you customize HTTPTransport, this feature will not take effect. I don’t know much about httpx, and I don’t know if this is a bug. , or there is another reason for this setting.
I believe that if a user has configured a proxy, it should be ensured that the proxy is applied. It took me 5 hours to find the reason for the issue, and I hope this modification can save time for other users."