st1vms / unofficial-claude-api

Unofficial Claude API supporting direct HTTP chat creation/deletion/retrieval, messages with multiple file attachments and auto session gathering using Firefox with geckodriver.
MIT License
131 stars 12 forks source link

add socks proxy support #16

Closed kyhhdm closed 9 months ago

kyhhdm commented 9 months ago

Since I have to use unofficial-claude2-api through a socks proxy, this patch might also be helpful for others in the similar situation.

st1vms commented 9 months ago

Thanks so much for the improvement, although there are a couple of things I'd like to address before merging...

I'm thinking of modifying the __get_proxy logic, using a class extension strategy for HTTPProxy and another possible proxy class which could be called SOCKSProxy and derives from the same base class as HTTPProxy.

So that users can simply import the corresponding class, configure it and provide it to the ClaudeAPIClient constructor.

I'll push directly to this PR once I finished the changes.

st1vms commented 9 months ago

@kyhhdm Can you please give a try to this new commit?

You now need to import SOCKSProxy out of claude2_api.client and construct it using:

If you'd like to use HTTPProxy instead, import it as usual, and set the ip,port and use_ssl parameter.

kyhhdm commented 9 months ago

I tested with the new commit with my socks5 proxy, it works well~

st1vms commented 9 months ago

Glad to hear that 👍

Merging right away!