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
d057ad3a
authored
Aug 27, 2024
by
heheer
Committed by
GitHub
Aug 27, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: global variable persist during api calls (#2544)
parent
a206d772
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
packages/service/core/chat/controller.ts
+21
-1
projects/app/src/pages/api/v1/chat/completions.ts
+17
-3
No files found.
packages/service/core/chat/controller.ts
View file @
d057ad3a
...
@@ -5,6 +5,7 @@ import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/c
...
@@ -5,6 +5,7 @@ import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/c
import
{
delFileByFileIdList
,
getGFSCollection
}
from
'../../common/file/gridfs/controller'
;
import
{
delFileByFileIdList
,
getGFSCollection
}
from
'../../common/file/gridfs/controller'
;
import
{
BucketNameEnum
}
from
'@fastgpt/global/common/file/constants'
;
import
{
BucketNameEnum
}
from
'@fastgpt/global/common/file/constants'
;
import
{
MongoChat
}
from
'./chatSchema'
;
import
{
MongoChat
}
from
'./chatSchema'
;
import
{
ChatSchema
as
ChatType
}
from
'@fastgpt/global/core/chat/type.d'
;
export
async
function
getChatItems
({
export
async
function
getChatItems
({
appId
,
appId
,
...
@@ -35,7 +36,26 @@ export async function getChatItems({
...
@@ -35,7 +36,26 @@ export async function getChatItems({
return
{
histories
};
return
{
histories
};
}
}
/* 临时适配旧的对话记录 */
export
async
function
getChat
({
appId
,
chatId
,
field
}:
{
appId
:
string
;
chatId
?:
string
;
field
:
string
;
}):
Promise
<
{
chat
:
ChatType
|
null
}
>
{
if
(
!
chatId
)
{
return
{
chat
:
null
};
}
const
chat
=
await
MongoChat
.
findOne
({
appId
,
chatId
},
field
).
lean
();
return
{
chat
};
}
/* Temporary adaptation for old conversation records */
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/pages/api/v1/chat/completions.ts
View file @
d057ad3a
...
@@ -20,7 +20,7 @@ import {
...
@@ -20,7 +20,7 @@ import {
textAdaptGptResponse
textAdaptGptResponse
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
}
from
'@fastgpt/global/core/workflow/runtime/utils'
;
import
{
GPTMessages2Chats
,
chatValue2RuntimePrompt
}
from
'@fastgpt/global/core/chat/adapt'
;
import
{
GPTMessages2Chats
,
chatValue2RuntimePrompt
}
from
'@fastgpt/global/core/chat/adapt'
;
import
{
getChatItems
}
from
'@fastgpt/service/core/chat/controller'
;
import
{
getChat
,
getChat
Items
}
from
'@fastgpt/service/core/chat/controller'
;
import
{
saveChat
}
from
'@fastgpt/service/core/chat/saveChat'
;
import
{
saveChat
}
from
'@fastgpt/service/core/chat/saveChat'
;
import
{
responseWrite
}
from
'@fastgpt/service/common/response'
;
import
{
responseWrite
}
from
'@fastgpt/service/common/response'
;
import
{
pushChatUsage
}
from
'@/service/support/wallet/usage/push'
;
import
{
pushChatUsage
}
from
'@/service/support/wallet/usage/push'
;
...
@@ -220,17 +220,31 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -220,17 +220,31 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
// Get and concat history;
// Get and concat history;
const
limit
=
getMaxHistoryLimitFromNodes
(
app
.
modules
);
const
limit
=
getMaxHistoryLimitFromNodes
(
app
.
modules
);
const
[{
histories
},
{
nodes
,
edges
,
chatConfig
}]
=
await
Promise
.
all
([
const
[{
histories
},
{
nodes
,
edges
,
chatConfig
}
,
{
chat
}
]
=
await
Promise
.
all
([
getChatItems
({
getChatItems
({
appId
:
app
.
_id
,
appId
:
app
.
_id
,
chatId
,
chatId
,
limit
,
limit
,
field
:
`dataId obj value nodeOutputs`
field
:
`dataId obj value nodeOutputs`
}),
}),
getAppLatestVersion
(
app
.
_id
,
app
)
getAppLatestVersion
(
app
.
_id
,
app
),
getChat
({
appId
:
app
.
_id
,
chatId
,
field
:
'source variableList variables'
})
]);
]);
// get chat histories
const
newHistories
=
concatHistories
(
histories
,
chatMessages
);
const
newHistories
=
concatHistories
(
histories
,
chatMessages
);
// get global variables
if
(
chat
&&
chat
.
variables
)
{
variables
=
{
...
chat
.
variables
,
...
variables
};
}
// Get runtimeNodes
// Get runtimeNodes
let
runtimeNodes
=
storeNodes2RuntimeNodes
(
nodes
,
getWorkflowEntryNodeIds
(
nodes
,
newHistories
));
let
runtimeNodes
=
storeNodes2RuntimeNodes
(
nodes
,
getWorkflowEntryNodeIds
(
nodes
,
newHistories
));
...
...
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