replicate-python icon indicating copy to clipboard operation
replicate-python copied to clipboard

add proxy

Open xmduhan opened this issue 1 year ago • 4 comments

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."

xmduhan avatar Apr 20 '24 08:04 xmduhan

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?

mattt avatar Apr 22 '24 10:04 mattt

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 avatar Apr 23 '24 07:04 xmduhan

@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.

mattt avatar Apr 23 '24 11:04 mattt

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.

xmduhan avatar Apr 24 '24 06:04 xmduhan