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

feat: add request with proxy support for chatgpt #78

Closed
wants to merge 1 commit into from

Conversation

wlemuel
Copy link

@wlemuel wlemuel commented Dec 10, 2022

No description provided.

@@ -11,3 +11,4 @@

# see the readme for how to find this
SESSION_TOKEN=
PROXY_URL=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.env.example is for required env variables; that is why CI is failing right now

@@ -1,5 +1,6 @@
import ExpiryMap from 'expiry-map'
import pTimeout, { TimeoutError } from 'p-timeout'
import { ProxyAgent, setGlobalDispatcher } from 'undici'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use undici directly because this package supports more than just node.js.

E.g., we use the default fetch implementation if one's available globally, and we only fallback to undici if we have to for node.js 16/17.

@@ -67,6 +75,11 @@ export class ChatGPTAPI {

this._accessTokenCache = new ExpiryMap<string, string>(accessTokenTTL)

if (proxyUrl) {
this._proxyAgent = new ProxyAgent(proxyUrl)
setGlobalDispatcher(this._proxyAgent)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to set a global dispatcher which will affect the whole process; rather, the proxy should only affect our usage of fetch within this module.

@transitive-bullshit
Copy link
Owner

Thanks @wlemuel 🙏

I think this is a great start to adding this feature, but the major blocker right now is that this implementation would drop support for environments other than node.js (like edge functions, browsers, deno, etc.).

@wlemuel
Copy link
Author

wlemuel commented Dec 11, 2022

Hi, @transitive-bullshit

Thanks for mentioning the compatibility issue, I will take into consideration the different runtime environments and find the best solution for compatibility

Since this will take some time, I would like to close this pull request temporarily.

@wlemuel wlemuel closed this Dec 11, 2022
@transitive-bullshit
Copy link
Owner

@wlemuel sounds good; I really do appreciate your help and am looking forward to another PR 😄 🙏

cyhhao pushed a commit to cyhhao/chatgpt-api that referenced this pull request Feb 8, 2023
…ti-platform

👷 Add muti-platform support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants