Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add socks proxy support #16

Merged
merged 3 commits into from
Feb 6, 2024
Merged

add socks proxy support #16

merged 3 commits into from
Feb 6, 2024

Conversation

kyhhdm
Copy link
Contributor

@kyhhdm kyhhdm commented Feb 5, 2024

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 st1vms self-assigned this Feb 5, 2024
@st1vms st1vms added the enhancement New feature or request label Feb 5, 2024
@st1vms
Copy link
Owner

st1vms commented Feb 5, 2024

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

  • The use_socks option should be set to False by default.
  • http scheme should also be covered when routing via SOCKS proxy.
  • There should also be an integer version number option for using SOCKS4 or SOCKS5.

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
Copy link
Owner

st1vms commented Feb 5, 2024

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

  • proxy_ip
  • proxy_port
  • version_num which can be either 4 or 5 (defaults to 4).

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

@kyhhdm
Copy link
Contributor Author

kyhhdm commented Feb 6, 2024

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

@st1vms
Copy link
Owner

st1vms commented Feb 6, 2024

Glad to hear that 👍

Merging right away!

@st1vms st1vms merged commit e42ee66 into st1vms:main Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants