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
8e8ceb74
authored
May 20, 2024
by
Archer
Committed by
GitHub
May 20, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add request log and uncatch error tip. (#1531)
parent
e35ce2ca
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
51 additions
and
32 deletions
+51
-32
Dockerfile
+2
-2
packages/global/core/workflow/runtime/utils.ts
+18
-1
packages/service/common/middle/entry.ts
+6
-0
packages/service/common/system/tools.ts
+12
-0
packages/service/core/chat/controller.ts
+1
-1
projects/app/src/components/core/workflow/Flow/ChatTest.tsx
+3
-13
projects/app/src/pages/api/v1/chat/completions.ts
+3
-1
projects/app/src/pages/app/detail/components/SimpleEdit/ChatTest.tsx
+4
-14
projects/app/src/service/mongo.ts
+2
-0
No files found.
Dockerfile
View file @
8e8ceb74
...
@@ -86,4 +86,4 @@ USER nextjs
...
@@ -86,4 +86,4 @@ USER nextjs
ENV
serverPath=./projects/$name/server.js
ENV
serverPath=./projects/$name/server.js
ENTRYPOINT
["sh","-c","node ${serverPath}"]
ENTRYPOINT
["sh","-c","node --max-old-space-size=4096 ${serverPath}"]
\ No newline at end of file
\ No newline at end of file
packages/global/core/workflow/runtime/utils.ts
View file @
8e8ceb74
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'../../ai/constants'
;
import
{
ChatCompletionRequestMessageRoleEnum
}
from
'../../ai/constants'
;
import
{
NodeOutputKeyEnum
}
from
'../constants'
;
import
{
Node
InputKeyEnum
,
Node
OutputKeyEnum
}
from
'../constants'
;
import
{
FlowNodeTypeEnum
}
from
'../node/constant'
;
import
{
FlowNodeTypeEnum
}
from
'../node/constant'
;
import
{
StoreNodeItemType
}
from
'../type'
;
import
{
StoreNodeItemType
}
from
'../type'
;
import
{
StoreEdgeItemType
}
from
'../type/edge'
;
import
{
StoreEdgeItemType
}
from
'../type/edge'
;
...
@@ -8,6 +8,23 @@ import { VARIABLE_NODE_ID } from '../constants';
...
@@ -8,6 +8,23 @@ import { VARIABLE_NODE_ID } from '../constants';
import
{
isReferenceValue
}
from
'../utils'
;
import
{
isReferenceValue
}
from
'../utils'
;
import
{
ReferenceValueProps
}
from
'../type/io'
;
import
{
ReferenceValueProps
}
from
'../type/io'
;
export
const
getMaxHistoryLimitFromNodes
=
(
nodes
:
StoreNodeItemType
[]):
number
=>
{
let
limit
=
10
;
nodes
.
forEach
((
node
)
=>
{
node
.
inputs
.
forEach
((
input
)
=>
{
if
(
(
input
.
key
===
NodeInputKeyEnum
.
history
||
input
.
key
===
NodeInputKeyEnum
.
historyMaxAmount
)
&&
typeof
input
.
value
===
'number'
)
{
limit
=
Math
.
max
(
limit
,
input
.
value
);
}
});
});
return
limit
*
2
;
};
export
const
initWorkflowEdgeStatus
=
(
edges
:
StoreEdgeItemType
[]):
RuntimeEdgeItemType
[]
=>
{
export
const
initWorkflowEdgeStatus
=
(
edges
:
StoreEdgeItemType
[]):
RuntimeEdgeItemType
[]
=>
{
return
(
return
(
edges
?.
map
((
edge
)
=>
({
edges
?.
map
((
edge
)
=>
({
...
...
packages/service/common/middle/entry.ts
View file @
8e8ceb74
...
@@ -2,6 +2,7 @@ import { jsonRes } from '../response';
...
@@ -2,6 +2,7 @@ import { jsonRes } from '../response';
import
type
{
NextApiResponse
}
from
'next'
;
import
type
{
NextApiResponse
}
from
'next'
;
import
{
withNextCors
}
from
'./cors'
;
import
{
withNextCors
}
from
'./cors'
;
import
{
ApiRequestProps
}
from
'../../type/next'
;
import
{
ApiRequestProps
}
from
'../../type/next'
;
import
{
addLog
}
from
'../system/log'
;
export
type
NextApiHandler
<
T
=
any
>
=
(
export
type
NextApiHandler
<
T
=
any
>
=
(
req
:
ApiRequestProps
,
req
:
ApiRequestProps
,
...
@@ -11,6 +12,8 @@ export type NextApiHandler<T = any> = (
...
@@ -11,6 +12,8 @@ export type NextApiHandler<T = any> = (
export
const
NextEntry
=
({
beforeCallback
=
[]
}:
{
beforeCallback
?:
Promise
<
any
>
[]
})
=>
{
export
const
NextEntry
=
({
beforeCallback
=
[]
}:
{
beforeCallback
?:
Promise
<
any
>
[]
})
=>
{
return
(...
args
:
NextApiHandler
[]):
NextApiHandler
=>
{
return
(...
args
:
NextApiHandler
[]):
NextApiHandler
=>
{
return
async
function
api
(
req
:
ApiRequestProps
,
res
:
NextApiResponse
)
{
return
async
function
api
(
req
:
ApiRequestProps
,
res
:
NextApiResponse
)
{
const
start
=
Date
.
now
();
addLog
.
info
(
`Request start
${
req
.
url
}
`
);
try
{
try
{
await
Promise
.
all
([
withNextCors
(
req
,
res
),
...
beforeCallback
]);
await
Promise
.
all
([
withNextCors
(
req
,
res
),
...
beforeCallback
]);
...
@@ -20,6 +23,9 @@ export const NextEntry = ({ beforeCallback = [] }: { beforeCallback?: Promise<an
...
@@ -20,6 +23,9 @@ export const NextEntry = ({ beforeCallback = [] }: { beforeCallback?: Promise<an
}
}
const
contentType
=
res
.
getHeader
(
'Content-Type'
);
const
contentType
=
res
.
getHeader
(
'Content-Type'
);
addLog
.
info
(
`Request finish
${
req
.
url
}
, time:
${
Date
.
now
()
-
start
}
ms`
);
if
((
!
contentType
||
contentType
===
'application/json'
)
&&
!
res
.
writableFinished
)
{
if
((
!
contentType
||
contentType
===
'application/json'
)
&&
!
res
.
writableFinished
)
{
return
jsonRes
(
res
,
{
return
jsonRes
(
res
,
{
code
:
200
,
code
:
200
,
...
...
packages/service/common/system/tools.ts
View file @
8e8ceb74
...
@@ -20,3 +20,15 @@ export const initFastGPTConfig = (config?: FastGPTConfigFileType) => {
...
@@ -20,3 +20,15 @@ export const initFastGPTConfig = (config?: FastGPTConfigFileType) => {
global
.
whisperModel
=
config
.
whisperModel
;
global
.
whisperModel
=
config
.
whisperModel
;
global
.
reRankModels
=
config
.
reRankModels
;
global
.
reRankModels
=
config
.
reRankModels
;
};
};
export
const
systemStartCb
=
()
=>
{
process
.
on
(
'uncaughtException'
,
(
err
)
=>
{
console
.
error
(
'Uncaught Exception:'
,
err
);
// process.exit(1); // 退出进程
});
process
.
on
(
'unhandledRejection'
,
(
reason
,
promise
)
=>
{
console
.
error
(
'Unhandled Rejection at:'
,
promise
,
'reason:'
,
reason
);
// process.exit(1); // 退出进程
});
};
packages/service/core/chat/controller.ts
View file @
8e8ceb74
...
@@ -32,7 +32,7 @@ export async function getChatItems({
...
@@ -32,7 +32,7 @@ export async function getChatItems({
return
{
history
};
return
{
history
};
}
}
/* 临时适配旧的对话记录
,清洗完数据后可删除(4.30刪除)
*/
/* 临时适配旧的对话记录 */
export
const
adaptStringValue
=
(
value
:
any
):
ChatItemValueItemType
[]
=>
{
export
const
adaptStringValue
=
(
value
:
any
):
ChatItemValueItemType
[]
=>
{
if
(
typeof
value
===
'string'
)
{
if
(
typeof
value
===
'string'
)
{
return
[
return
[
...
...
projects/app/src/components/core/workflow/Flow/ChatTest.tsx
View file @
8e8ceb74
...
@@ -25,6 +25,7 @@ import { useTranslation } from 'next-i18next';
...
@@ -25,6 +25,7 @@ import { useTranslation } from 'next-i18next';
import
{
StoreEdgeItemType
}
from
'@fastgpt/global/core/workflow/type/edge'
;
import
{
StoreEdgeItemType
}
from
'@fastgpt/global/core/workflow/type/edge'
;
import
{
import
{
getDefaultEntryNodeIds
,
getDefaultEntryNodeIds
,
getMaxHistoryLimitFromNodes
,
initWorkflowEdgeStatus
,
initWorkflowEdgeStatus
,
storeNodes2RuntimeNodes
storeNodes2RuntimeNodes
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
...
@@ -57,19 +58,8 @@ const ChatTest = (
...
@@ -57,19 +58,8 @@ const ChatTest = (
const
startChat
=
useCallback
(
const
startChat
=
useCallback
(
async
({
chatList
,
controller
,
generatingMessage
,
variables
}:
StartChatFnProps
)
=>
{
async
({
chatList
,
controller
,
generatingMessage
,
variables
}:
StartChatFnProps
)
=>
{
/* get histories */
/* get histories */
let
historyMaxLen
=
6
;
let
historyMaxLen
=
getMaxHistoryLimitFromNodes
(
nodes
);
nodes
.
forEach
((
node
)
=>
{
const
history
=
chatList
.
slice
(
-
historyMaxLen
-
2
,
-
2
);
node
.
inputs
.
forEach
((
input
)
=>
{
if
(
(
input
.
key
===
NodeInputKeyEnum
.
history
||
input
.
key
===
NodeInputKeyEnum
.
historyMaxAmount
)
&&
typeof
input
.
value
===
'number'
)
{
historyMaxLen
=
Math
.
max
(
historyMaxLen
,
input
.
value
);
}
});
});
const
history
=
chatList
.
slice
(
-
(
historyMaxLen
*
2
)
-
2
,
-
2
);
// 流请求,获取数据
// 流请求,获取数据
const
{
responseText
,
responseData
,
newVariables
}
=
await
streamFetch
({
const
{
responseText
,
responseData
,
newVariables
}
=
await
streamFetch
({
...
...
projects/app/src/pages/api/v1/chat/completions.ts
View file @
8e8ceb74
...
@@ -10,6 +10,7 @@ import type { ChatCompletionCreateParams } from '@fastgpt/global/core/ai/type.d'
...
@@ -10,6 +10,7 @@ import type { ChatCompletionCreateParams } from '@fastgpt/global/core/ai/type.d'
import
type
{
ChatCompletionMessageParam
}
from
'@fastgpt/global/core/ai/type.d'
;
import
type
{
ChatCompletionMessageParam
}
from
'@fastgpt/global/core/ai/type.d'
;
import
{
import
{
getDefaultEntryNodeIds
,
getDefaultEntryNodeIds
,
getMaxHistoryLimitFromNodes
,
initWorkflowEdgeStatus
,
initWorkflowEdgeStatus
,
storeNodes2RuntimeNodes
,
storeNodes2RuntimeNodes
,
textAdaptGptResponse
textAdaptGptResponse
...
@@ -168,11 +169,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -168,11 +169,12 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
})();
})();
// 1. get and concat history; 2. get app workflow
// 1. get and concat history; 2. get app workflow
const
limit
=
getMaxHistoryLimitFromNodes
(
app
.
modules
);
const
[{
history
},
{
nodes
,
edges
}]
=
await
Promise
.
all
([
const
[{
history
},
{
nodes
,
edges
}]
=
await
Promise
.
all
([
getChatItems
({
getChatItems
({
appId
:
app
.
_id
,
appId
:
app
.
_id
,
chatId
,
chatId
,
limit
:
30
,
limit
,
field
:
`dataId obj value`
field
:
`dataId obj value`
}),
}),
getAppLatestVersion
(
app
.
_id
,
app
)
getAppLatestVersion
(
app
.
_id
,
app
)
...
...
projects/app/src/pages/app/detail/components/SimpleEdit/ChatTest.tsx
View file @
8e8ceb74
...
@@ -4,7 +4,6 @@ import { useTranslation } from 'next-i18next';
...
@@ -4,7 +4,6 @@ import { useTranslation } from 'next-i18next';
import
React
,
{
useCallback
,
useEffect
,
useRef
}
from
'react'
;
import
React
,
{
useCallback
,
useEffect
,
useRef
}
from
'react'
;
import
ChatBox
from
'@/components/ChatBox'
;
import
ChatBox
from
'@/components/ChatBox'
;
import
type
{
ComponentRef
,
StartChatFnProps
}
from
'@/components/ChatBox/type.d'
;
import
type
{
ComponentRef
,
StartChatFnProps
}
from
'@/components/ChatBox/type.d'
;
import
{
NodeInputKeyEnum
}
from
'@fastgpt/global/core/workflow/constants'
;
import
{
streamFetch
}
from
'@/web/common/api/fetch'
;
import
{
streamFetch
}
from
'@/web/common/api/fetch'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
import
MyIcon
from
'@fastgpt/web/components/common/Icon'
;
...
@@ -13,6 +12,7 @@ import { checkChatSupportSelectFileByModules } from '@/web/core/chat/utils';
...
@@ -13,6 +12,7 @@ import { checkChatSupportSelectFileByModules } from '@/web/core/chat/utils';
import
{
AppTypeEnum
}
from
'@fastgpt/global/core/app/constants'
;
import
{
AppTypeEnum
}
from
'@fastgpt/global/core/app/constants'
;
import
{
import
{
getDefaultEntryNodeIds
,
getDefaultEntryNodeIds
,
getMaxHistoryLimitFromNodes
,
initWorkflowEdgeStatus
,
initWorkflowEdgeStatus
,
storeNodes2RuntimeNodes
storeNodes2RuntimeNodes
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
...
@@ -53,19 +53,9 @@ const ChatTest = ({
...
@@ -53,19 +53,9 @@ const ChatTest = ({
if
(
!
workflowData
)
return
Promise
.
reject
(
'workflowData is empty'
);
if
(
!
workflowData
)
return
Promise
.
reject
(
'workflowData is empty'
);
/* get histories */
/* get histories */
let
historyMaxLen
=
6
;
let
historyMaxLen
=
getMaxHistoryLimitFromNodes
(
workflowData
.
nodes
);
workflowData
?.
nodes
.
forEach
((
node
)
=>
{
node
.
inputs
.
forEach
((
input
)
=>
{
const
history
=
chatList
.
slice
(
-
historyMaxLen
-
2
,
-
2
);
if
(
(
input
.
key
===
NodeInputKeyEnum
.
history
||
input
.
key
===
NodeInputKeyEnum
.
historyMaxAmount
)
&&
typeof
input
.
value
===
'number'
)
{
historyMaxLen
=
Math
.
max
(
historyMaxLen
,
input
.
value
);
}
});
});
const
history
=
chatList
.
slice
(
-
(
historyMaxLen
*
2
)
-
2
,
-
2
);
// 流请求,获取数据
// 流请求,获取数据
const
{
responseText
,
responseData
}
=
await
streamFetch
({
const
{
responseText
,
responseData
}
=
await
streamFetch
({
...
...
projects/app/src/service/mongo.ts
View file @
8e8ceb74
...
@@ -11,6 +11,7 @@ import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
...
@@ -11,6 +11,7 @@ import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
import
{
initGlobal
}
from
'./common/system'
;
import
{
initGlobal
}
from
'./common/system'
;
import
{
startMongoWatch
}
from
'./common/system/volumnMongoWatch'
;
import
{
startMongoWatch
}
from
'./common/system/volumnMongoWatch'
;
import
{
startTrainingQueue
}
from
'./core/dataset/training/utils'
;
import
{
startTrainingQueue
}
from
'./core/dataset/training/utils'
;
import
{
systemStartCb
}
from
'@fastgpt/service/common/system/tools'
;
/**
/**
* connect MongoDB and init data
* connect MongoDB and init data
...
@@ -21,6 +22,7 @@ export function connectToDatabase(): Promise<void> {
...
@@ -21,6 +22,7 @@ export function connectToDatabase(): Promise<void> {
initGlobal
();
initGlobal
();
},
},
afterHook
:
async
()
=>
{
afterHook
:
async
()
=>
{
systemStartCb
();
// init system config
// init system config
getInitConfig
();
getInitConfig
();
//init vector database, init root user
//init vector database, init root user
...
...
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