Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Chatgpt Forwarder
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Chatgpt Forwarder
Commits
6a39e6b0
Commit
6a39e6b0
authored
Feb 10, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy pool
parent
7c31177e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
3 deletions
+46
-3
config.example.yaml
config.example.yaml
+2
-1
src/app.module.ts
src/app.module.ts
+2
-1
src/chatgpt/chatgpt.service.ts
src/chatgpt/chatgpt.service.ts
+4
-1
src/proxy-pool/proxy-pool.service.spec.ts
src/proxy-pool/proxy-pool.service.spec.ts
+18
-0
src/proxy-pool/proxy-pool.service.ts
src/proxy-pool/proxy-pool.service.ts
+19
-0
src/utility/config.ts
src/utility/config.ts
+1
-0
No files found.
config.example.yaml
View file @
6a39e6b0
...
...
@@ -7,3 +7,4 @@ accounts:
password
:
'
wwww'
pro
:
false
loginType
:
'
default'
proxies
:
[]
\ No newline at end of file
src/app.module.ts
View file @
6a39e6b0
...
...
@@ -6,6 +6,7 @@ import { AragamiModule } from 'nestjs-aragami';
import
{
ChatgptService
}
from
'
./chatgpt/chatgpt.service
'
;
import
{
ConversationService
}
from
'
./conversation/conversation.service
'
;
import
{
AuthService
}
from
'
./auth/auth.service
'
;
import
{
ProxyPoolService
}
from
'
./proxy-pool/proxy-pool.service
'
;
@
Module
({
imports
:
[
...
...
@@ -31,6 +32,6 @@ import { AuthService } from './auth/auth.service';
}),
],
controllers
:
[
AppController
],
providers
:
[
ChatgptService
,
ConversationService
,
AuthService
],
providers
:
[
ChatgptService
,
ConversationService
,
AuthService
,
ProxyPoolService
],
})
export
class
AppModule
{}
src/chatgpt/chatgpt.service.ts
View file @
6a39e6b0
...
...
@@ -15,6 +15,7 @@ import { BetterLock } from 'better-lock/dist/better_lock';
import
_
from
'
lodash
'
;
import
{
BlankReturnMessageDto
}
from
'
../dto/ReturnMessage.dto
'
;
import
pTimeout
from
'
p-timeout
'
;
import
{
ProxyPoolService
}
from
'
../proxy-pool/proxy-pool.service
'
;
interface
AccountState
{
email
:
string
;
...
...
@@ -31,6 +32,7 @@ export class ChatgptService
constructor
(
private
config
:
ConfigService
,
private
conversationService
:
ConversationService
,
private
proxyPoolService
:
ProxyPoolService
,
)
{
super
(
'
ChatGPT
'
);
}
...
...
@@ -46,6 +48,7 @@ export class ChatgptService
isProAccount
:
!!
account
.
pro
,
isGoogleLogin
:
account
.
loginType
===
'
google
'
,
isMicrosoftLogin
:
account
.
loginType
===
'
microsoft
'
,
proxyServer
:
this
.
proxyPoolService
.
getProxy
(),
});
try
{
await
pTimeout
(
instance
.
initSession
(),
600000
);
...
...
@@ -59,7 +62,7 @@ export class ChatgptService
}
catch
(
e
)
{
this
.
error
(
`Failed to initialize ChatGPT API for
${
account
.
email
}
`
,
e
);
await
Promise
.
all
([
new
Promise
((
r
)
=>
setTimeout
(
r
,
60
000
)),
new
Promise
((
r
)
=>
setTimeout
(
r
,
5
000
)),
instance
.
closeSession
().
catch
(),
]);
return
this
.
initAccount
(
account
);
...
...
src/proxy-pool/proxy-pool.service.spec.ts
0 → 100644
View file @
6a39e6b0
import
{
Test
,
TestingModule
}
from
'
@nestjs/testing
'
;
import
{
ProxyPoolService
}
from
'
./proxy-pool.service
'
;
describe
(
'
ProxyPoolService
'
,
()
=>
{
let
service
:
ProxyPoolService
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
providers
:
[
ProxyPoolService
],
}).
compile
();
service
=
module
.
get
<
ProxyPoolService
>
(
ProxyPoolService
);
});
it
(
'
should be defined
'
,
()
=>
{
expect
(
service
).
toBeDefined
();
});
});
src/proxy-pool/proxy-pool.service.ts
0 → 100644
View file @
6a39e6b0
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
@
Injectable
()
export
class
ProxyPoolService
{
private
pointer
=
0
;
private
proxies
=
this
.
config
.
get
<
string
[]
>
(
'
proxies
'
);
constructor
(
private
config
:
ConfigService
)
{}
getProxy
()
{
if
(
!
this
.
proxies
?.
length
)
{
return
;
}
if
(
this
.
pointer
>=
this
.
proxies
.
length
)
{
this
.
pointer
=
0
;
}
return
this
.
proxies
[
this
.
pointer
++
];
}
}
src/utility/config.ts
View file @
6a39e6b0
...
...
@@ -14,6 +14,7 @@ const defaultConfig = {
accounts
:
[]
as
OpenAIAccount
[],
redisUrl
:
''
,
token
:
''
,
proxies
:
[]
as
string
[],
};
export
type
Config
=
typeof
defaultConfig
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment