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
188aa128
Commit
188aa128
authored
Feb 14, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refa provider
parent
f227084d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
42 deletions
+46
-42
src/account-pool/account-pool.service.ts
src/account-pool/account-pool.service.ts
+1
-1
src/account-provider/account-provider.service.ts
src/account-provider/account-provider.service.ts
+5
-10
src/datasource/base-provider.ts
src/datasource/base-provider.ts
+22
-0
src/datasource/datasource.ts
src/datasource/datasource.ts
+4
-18
src/davinci/davinci.service.ts
src/davinci/davinci.service.ts
+5
-2
src/key-provider/key-provider.service.ts
src/key-provider/key-provider.service.ts
+4
-5
src/proxy-pool/proxy-pool.service.ts
src/proxy-pool/proxy-pool.service.ts
+1
-1
src/proxy-provider/proxy-provider.service.ts
src/proxy-provider/proxy-provider.service.ts
+4
-5
No files found.
src/account-pool/account-pool.service.ts
View file @
188aa128
...
...
@@ -64,7 +64,7 @@ export class AccountPoolService
this
.
ChatGPTAPIBrowserConstructor
=
(
await
eval
(
"
import('chatgpt3')
"
)
).
ChatGPTAPIBrowser
;
this
.
accountInfos
=
await
this
.
accountProvider
.
get
Accounts
();
this
.
accountInfos
=
await
this
.
accountProvider
.
get
();
this
.
accountInfos
.
forEach
((
a
)
=>
this
.
initAccount
(
a
));
}
...
...
src/account-provider/account-provider.service.ts
View file @
188aa128
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
OpenAIAccount
}
from
'
../utility/config
'
;
import
{
fetchDatasource
}
from
'
../datasource/datasource
'
;
import
{
BaseProvider
}
from
'
../datasource/base-provider
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
@
Injectable
()
export
class
AccountProviderService
{
constructor
(
private
config
:
ConfigService
)
{}
async
getAccounts
()
{
return
(
(
await
fetchDatasource
<
OpenAIAccount
[]
>
(
this
.
config
.
get
(
'
accounts
'
)))
||
[]
);
export
class
AccountProviderService
extends
BaseProvider
<
OpenAIAccount
[]
>
{
constructor
(
config
:
ConfigService
)
{
super
(
config
,
'
accounts
'
);
}
async
writeBack
(
accounts
:
OpenAIAccount
[],
type
:
'
add
'
|
'
remove
'
,
...
...
src/datasource/base-provider.ts
0 → 100644
View file @
188aa128
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
DatasourceConfig
,
Datasources
}
from
'
./datasource
'
;
export
class
BaseProvider
<
T
>
{
constructor
(
protected
config
:
ConfigService
,
protected
key
:
string
)
{}
async
get
():
Promise
<
T
>
{
const
config
=
this
.
config
.
get
<
DatasourceConfig
<
T
>>
(
this
.
key
);
if
(
!
config
)
{
return
;
}
if
(
Array
.
isArray
(
config
))
{
// legacy config
return
config
as
T
;
}
const
Datasource
=
Datasources
.
get
(
config
.
type
);
if
(
!
Datasource
)
{
throw
new
Error
(
`Unknown datasource type:
${
config
.
type
}
`
);
}
return
new
Datasource
(
config
.
config
).
getData
();
}
}
src/datasource/datasource.ts
View file @
188aa128
...
...
@@ -6,7 +6,10 @@ export interface DatasourceConfigMap<T> {
static
:
T
;
api
:
{
endpoint
:
string
;
headers
:
Record
<
string
,
string
|
number
>
};
}
export
interface
DatasourceConfig
<
T
,
K
extends
keyof
DatasourceConfigMap
<
T
>>
{
export
interface
DatasourceConfig
<
T
,
K
extends
keyof
DatasourceConfigMap
<
T
>
=
keyof
DatasourceConfigMap
<
T
>
,
>
{
type
:
K
;
config
:
DatasourceConfigMap
<
T
>
[
K
];
}
...
...
@@ -20,20 +23,3 @@ export const Datasources = new Map<
Datasources
.
set
(
'
static
'
,
StaticDatasource
as
any
);
Datasources
.
set
(
'
api
'
,
ApiDatasource
as
any
);
export
async
function
fetchDatasource
<
T
>
(
config
:
DatasourceConfig
<
T
,
keyof
DatasourceConfigMap
<
any
>>
,
):
Promise
<
T
>
{
if
(
!
config
)
{
return
;
}
if
(
Array
.
isArray
(
config
))
{
// legacy config
return
config
as
any
;
}
const
Datasource
=
Datasources
.
get
(
config
.
type
);
if
(
!
Datasource
)
{
throw
new
Error
(
`Unknown datasource type:
${
config
.
type
}
`
);
}
return
new
Datasource
(
config
.
config
).
getData
();
}
src/davinci/davinci.service.ts
View file @
188aa128
...
...
@@ -19,7 +19,7 @@ export class DavinciService extends ConsoleLogger implements OnModuleInit {
private
pointer
=
0
;
private
async
getKey
(
exclude
:
string
[]
=
[])
{
const
excludeSet
=
new
Set
(
exclude
);
const
keys
=
(
await
this
.
keyProvider
.
get
Keys
()).
filter
(
const
keys
=
(
await
this
.
keyProvider
.
get
()).
filter
(
(
key
)
=>
!
excludeSet
.
has
(
key
),
);
if
(
!
keys
.
length
)
{
...
...
@@ -28,7 +28,10 @@ export class DavinciService extends ConsoleLogger implements OnModuleInit {
'
No available accounts.
'
,
).
toException
();
}
const
index
=
this
.
pointer
++
%
keys
.
length
;
if
(
this
.
pointer
>=
keys
.
length
)
{
this
.
pointer
=
0
;
}
const
index
=
this
.
pointer
++
;
return
keys
[
index
];
}
...
...
src/key-provider/key-provider.service.ts
View file @
188aa128
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
BaseProvider
}
from
'
../datasource/base-provider
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
fetchDatasource
}
from
'
../datasource/datasource
'
;
@
Injectable
()
export
class
KeyProviderService
{
constructor
(
private
config
:
ConfigService
)
{}
async
getKeys
()
{
return
(
await
fetchDatasource
<
string
[]
>
(
this
.
config
.
get
(
'
apiKeys
'
)))
||
[];
export
class
KeyProviderService
extends
BaseProvider
<
string
[]
>
{
constructor
(
config
:
ConfigService
)
{
super
(
config
,
'
apiKeys
'
);
}
}
src/proxy-pool/proxy-pool.service.ts
View file @
188aa128
...
...
@@ -7,7 +7,7 @@ export class ProxyPoolService {
constructor
(
private
proxyProvider
:
ProxyProviderService
)
{}
async
getProxy
()
{
const
proxies
=
await
this
.
proxyProvider
.
get
Proxies
();
const
proxies
=
await
this
.
proxyProvider
.
get
();
if
(
!
proxies
?.
length
)
{
return
;
}
...
...
src/proxy-provider/proxy-provider.service.ts
View file @
188aa128
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
BaseProvider
}
from
'
../datasource/base-provider
'
;
import
{
ConfigService
}
from
'
@nestjs/config
'
;
import
{
fetchDatasource
}
from
'
../datasource/datasource
'
;
@
Injectable
()
export
class
ProxyProviderService
{
constructor
(
private
config
:
ConfigService
)
{}
async
getProxies
()
{
return
(
await
fetchDatasource
<
string
[]
>
(
this
.
config
.
get
(
'
proxies
'
)))
||
[];
export
class
ProxyProviderService
extends
BaseProvider
<
string
[]
>
{
constructor
(
config
:
ConfigService
)
{
super
(
config
,
'
proxies
'
);
}
}
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