Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
705ac1c2
authored
Apr 08, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 专线代理配置
parent
52d00d05
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
52 additions
and
32 deletions
+52
-32
.env.template
+2
-2
src/pages/api/chat/chatGpt.ts
+1
-1
src/pages/api/chat/vectorGpt.ts
+1
-1
src/pages/api/model/data/fetchingUrlData.ts
+1
-1
src/pages/api/model/del.ts
+5
-3
src/pages/api/model/train/putTrainStatus.ts
+5
-3
src/pages/api/model/train/train.ts
+4
-4
src/pages/api/openapi/chat/lafGpt.ts
+2
-2
src/pages/api/openapi/chat/vectorGpt.ts
+1
-1
src/service/events/generateAbstract.ts
+1
-1
src/service/events/generateQA.ts
+1
-1
src/service/mongo.ts
+21
-2
src/service/utils/openai.ts
+1
-1
src/service/utils/tools.ts
+2
-9
src/types/index.d.ts
+4
-0
No files found.
.env.template
View file @
705ac1c2
AXIOS_PROXY_HOST=127.0.0.1
AXIOS_PROXY_HOST=127.0.0.1
AXIOS_PROXY_PORT
=3321
0
AXIOS_PROXY_PORT
_FAST=789
0
MONGODB_URI=
AXIOS_PROXY_PORT_NORMAL=7890
MY_MAIL=
MY_MAIL=
MAILE_CODE=
MAILE_CODE=
TOKEN_KEY=
TOKEN_KEY=
...
...
src/pages/api/chat/chatGpt.ts
View file @
705ac1c2
...
@@ -96,7 +96,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -96,7 +96,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{
{
timeout
:
40000
,
timeout
:
40000
,
responseType
:
'stream'
,
responseType
:
'stream'
,
httpsAgent
httpsAgent
:
httpsAgent
(
!
userApiKey
)
}
}
);
);
...
...
src/pages/api/chat/vectorGpt.ts
View file @
705ac1c2
...
@@ -141,7 +141,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -141,7 +141,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{
{
timeout
:
40000
,
timeout
:
40000
,
responseType
:
'stream'
,
responseType
:
'stream'
,
httpsAgent
httpsAgent
:
httpsAgent
(
!
userApiKey
)
}
}
);
);
...
...
src/pages/api/model/data/fetchingUrlData.ts
View file @
705ac1c2
...
@@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
data
=
await
axios
const
data
=
await
axios
.
get
(
url
,
{
.
get
(
url
,
{
httpsAgent
httpsAgent
:
httpsAgent
(
false
)
})
})
.
then
((
res
)
=>
res
.
data
as
string
);
.
then
((
res
)
=>
res
.
data
as
string
);
...
...
src/pages/api/model/del.ts
View file @
705ac1c2
...
@@ -68,12 +68,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -68,12 +68,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
if
(
training
)
{
if
(
training
)
{
const
{
openai
}
=
await
getUserApiOpenai
(
userId
);
const
{
openai
}
=
await
getUserApiOpenai
(
userId
);
// 获取训练记录
// 获取训练记录
const
tuneRecord
=
await
openai
.
retrieveFineTune
(
training
.
tuneId
,
{
httpsAgent
});
const
tuneRecord
=
await
openai
.
retrieveFineTune
(
training
.
tuneId
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// 删除训练文件
// 删除训练文件
openai
.
deleteFile
(
tuneRecord
.
data
.
training_files
[
0
].
id
,
{
httpsAgent
});
openai
.
deleteFile
(
tuneRecord
.
data
.
training_files
[
0
].
id
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// 取消训练
// 取消训练
openai
.
cancelFineTune
(
training
.
tuneId
,
{
httpsAgent
});
openai
.
cancelFineTune
(
training
.
tuneId
,
{
httpsAgent
:
httpsAgent
(
false
)
});
}
}
// 删除对应训练记录
// 删除对应训练记录
...
...
src/pages/api/model/train/putTrainStatus.ts
View file @
705ac1c2
...
@@ -46,11 +46,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -46,11 +46,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
{
openai
}
=
await
getUserApiOpenai
(
userId
);
const
{
openai
}
=
await
getUserApiOpenai
(
userId
);
// 获取 openai 的训练情况
// 获取 openai 的训练情况
const
{
data
}
=
await
openai
.
retrieveFineTune
(
training
.
tuneId
,
{
httpsAgent
});
const
{
data
}
=
await
openai
.
retrieveFineTune
(
training
.
tuneId
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// console.log(data);
// console.log(data);
if
(
data
.
status
===
OpenAiTuneStatusEnum
.
succeeded
)
{
if
(
data
.
status
===
OpenAiTuneStatusEnum
.
succeeded
)
{
// 删除训练文件
// 删除训练文件
openai
.
deleteFile
(
data
.
training_files
[
0
].
id
,
{
httpsAgent
});
openai
.
deleteFile
(
data
.
training_files
[
0
].
id
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// 更新模型状态和模型内容
// 更新模型状态和模型内容
await
Model
.
findByIdAndUpdate
(
modelId
,
{
await
Model
.
findByIdAndUpdate
(
modelId
,
{
...
@@ -75,7 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -75,7 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
/* 取消微调 */
/* 取消微调 */
if
(
data
.
status
===
OpenAiTuneStatusEnum
.
cancelled
)
{
if
(
data
.
status
===
OpenAiTuneStatusEnum
.
cancelled
)
{
// 删除训练文件
// 删除训练文件
openai
.
deleteFile
(
data
.
training_files
[
0
].
id
,
{
httpsAgent
});
openai
.
deleteFile
(
data
.
training_files
[
0
].
id
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// 更新模型
// 更新模型
await
Model
.
findByIdAndUpdate
(
modelId
,
{
await
Model
.
findByIdAndUpdate
(
modelId
,
{
...
...
src/pages/api/model/train/train.ts
View file @
705ac1c2
...
@@ -75,7 +75,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -75,7 +75,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// @ts-ignore
// @ts-ignore
fs
.
createReadStream
(
file
.
filepath
),
fs
.
createReadStream
(
file
.
filepath
),
'fine-tune'
,
'fine-tune'
,
{
httpsAgent
}
{
httpsAgent
:
httpsAgent
(
false
)
}
);
);
uploadFileId
=
uploadRes
.
data
.
id
;
// 记录上传文件的 ID
uploadFileId
=
uploadRes
.
data
.
id
;
// 记录上传文件的 ID
...
@@ -87,7 +87,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -87,7 +87,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
suffix
:
model
.
name
,
suffix
:
model
.
name
,
n_epochs
:
4
n_epochs
:
4
},
},
{
httpsAgent
}
{
httpsAgent
:
httpsAgent
(
false
)
}
);
);
trainId
=
trainRes
.
data
.
id
;
// 记录训练 ID
trainId
=
trainRes
.
data
.
id
;
// 记录训练 ID
...
@@ -117,9 +117,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -117,9 +117,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// @ts-ignore
// @ts-ignore
if
(
openai
)
{
if
(
openai
)
{
// @ts-ignore
// @ts-ignore
uploadFileId
&&
openai
.
deleteFile
(
uploadFileId
,
{
httpsAgent
});
uploadFileId
&&
openai
.
deleteFile
(
uploadFileId
,
{
httpsAgent
:
httpsAgent
(
false
)
});
// @ts-ignore
// @ts-ignore
trainId
&&
openai
.
cancelFineTune
(
trainId
,
{
httpsAgent
});
trainId
&&
openai
.
cancelFineTune
(
trainId
,
{
httpsAgent
:
httpsAgent
(
false
)
});
}
}
jsonRes
(
res
,
{
jsonRes
(
res
,
{
...
...
src/pages/api/openapi/chat/lafGpt.ts
View file @
705ac1c2
...
@@ -111,7 +111,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -111,7 +111,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
},
{
{
timeout
:
120000
,
timeout
:
120000
,
httpsAgent
httpsAgent
:
httpsAgent
(
true
)
}
}
);
);
...
@@ -201,7 +201,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -201,7 +201,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{
{
timeout
:
120000
,
timeout
:
120000
,
responseType
:
isStream
?
'stream'
:
'json'
,
responseType
:
isStream
?
'stream'
:
'json'
,
httpsAgent
httpsAgent
:
httpsAgent
(
true
)
}
}
);
);
...
...
src/pages/api/openapi/chat/vectorGpt.ts
View file @
705ac1c2
...
@@ -163,7 +163,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -163,7 +163,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{
{
timeout
:
120000
,
timeout
:
120000
,
responseType
:
isStream
?
'stream'
:
'json'
,
responseType
:
isStream
?
'stream'
:
'json'
,
httpsAgent
httpsAgent
:
httpsAgent
(
true
)
}
}
);
);
...
...
src/service/events/generateAbstract.ts
View file @
705ac1c2
...
@@ -76,7 +76,7 @@ export async function generateAbstract(next = false): Promise<any> {
...
@@ -76,7 +76,7 @@ export async function generateAbstract(next = false): Promise<any> {
},
},
{
{
timeout
:
120000
,
timeout
:
120000
,
httpsAgent
httpsAgent
:
httpsAgent
(
!
userApiKey
)
}
}
);
);
...
...
src/service/events/generateQA.ts
View file @
705ac1c2
...
@@ -91,7 +91,7 @@ export async function generateQA(next = false): Promise<any> {
...
@@ -91,7 +91,7 @@ export async function generateQA(next = false): Promise<any> {
},
},
{
{
timeout
:
180000
,
timeout
:
180000
,
httpsAgent
httpsAgent
:
httpsAgent
(
!
userApiKey
)
}
}
)
)
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
...
...
src/service/mongo.ts
View file @
705ac1c2
import
mongoose
from
'mongoose'
;
import
mongoose
from
'mongoose'
;
import
{
generateQA
}
from
'./events/generateQA'
;
import
{
generateQA
}
from
'./events/generateQA'
;
import
{
generateAbstract
}
from
'./events/generateAbstract'
;
import
{
generateVector
}
from
'./events/generateVector'
;
import
{
generateVector
}
from
'./events/generateVector'
;
import
tunnel
from
'tunnel'
;
/**
/**
* 连接 MongoDB 数据库
* 连接 MongoDB 数据库
...
@@ -28,8 +28,27 @@ export async function connectToDatabase(): Promise<void> {
...
@@ -28,8 +28,27 @@ export async function connectToDatabase(): Promise<void> {
}
}
generateQA
();
generateQA
();
// generateAbstract();
generateVector
(
true
);
generateVector
(
true
);
// 创建代理对象
if
(
process
.
env
.
AXIOS_PROXY_HOST
&&
process
.
env
.
AXIOS_PROXY_PORT_FAST
&&
process
.
env
.
AXIOS_PROXY_PORT_NORMAL
)
{
global
.
httpsAgentFast
=
tunnel
.
httpsOverHttp
({
proxy
:
{
host
:
process
.
env
.
AXIOS_PROXY_HOST
,
port
:
+
process
.
env
.
AXIOS_PROXY_PORT_FAST
}
});
global
.
httpsAgentNormal
=
tunnel
.
httpsOverHttp
({
proxy
:
{
host
:
process
.
env
.
AXIOS_PROXY_HOST
,
port
:
+
process
.
env
.
AXIOS_PROXY_PORT_NORMAL
}
});
}
}
}
export
*
from
'./models/authCode'
;
export
*
from
'./models/authCode'
;
...
...
src/service/utils/openai.ts
View file @
705ac1c2
...
@@ -85,7 +85,7 @@ export const openaiCreateEmbedding = async ({
...
@@ -85,7 +85,7 @@ export const openaiCreateEmbedding = async ({
},
},
{
{
timeout
:
60000
,
timeout
:
60000
,
httpsAgent
httpsAgent
:
httpsAgent
(
isPay
)
}
}
)
)
.
then
((
res
)
=>
({
.
then
((
res
)
=>
({
...
...
src/service/utils/tools.ts
View file @
705ac1c2
...
@@ -83,15 +83,8 @@ export const authOpenApiKey = async (req: NextApiRequest) => {
...
@@ -83,15 +83,8 @@ export const authOpenApiKey = async (req: NextApiRequest) => {
};
};
/* 代理 */
/* 代理 */
export
const
httpsAgent
=
export
const
httpsAgent
=
(
fast
:
boolean
)
=>
process
.
env
.
AXIOS_PROXY_HOST
&&
process
.
env
.
AXIOS_PROXY_PORT
fast
?
global
.
httpsAgentFast
:
global
.
httpsAgentNormal
;
?
tunnel
.
httpsOverHttp
({
proxy
:
{
host
:
process
.
env
.
AXIOS_PROXY_HOST
,
port
:
+
process
.
env
.
AXIOS_PROXY_PORT
}
})
:
undefined
;
/* tokens 截断 */
/* tokens 截断 */
export
const
openaiChatFilter
=
(
prompts
:
ChatItemType
[],
maxTokens
:
number
)
=>
{
export
const
openaiChatFilter
=
(
prompts
:
ChatItemType
[],
maxTokens
:
number
)
=>
{
...
...
src/types/index.d.ts
View file @
705ac1c2
import
type
{
Mongoose
}
from
'mongoose'
;
import
type
{
Mongoose
}
from
'mongoose'
;
import
type
{
RedisClientType
}
from
'redis'
;
import
type
{
RedisClientType
}
from
'redis'
;
import
type
{
Agent
}
from
'http'
;
declare
global
{
declare
global
{
var
mongodb
:
Mongoose
|
string
|
null
;
var
mongodb
:
Mongoose
|
string
|
null
;
...
@@ -8,6 +9,9 @@ declare global {
...
@@ -8,6 +9,9 @@ declare global {
var
generatingAbstract
:
boolean
;
var
generatingAbstract
:
boolean
;
var
generatingVector
:
boolean
;
var
generatingVector
:
boolean
;
var
QRCode
:
any
;
var
QRCode
:
any
;
var
httpsAgentFast
:
Agent
;
var
httpsAgentNormal
:
Agent
;
interface
Window
{
interface
Window
{
[
'pdfjs-dist/build/pdf'
]:
any
;
[
'pdfjs-dist/build/pdf'
]:
any
;
}
}
...
...
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