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
a75036b6
authored
Nov 26, 2024
by
Archer
Committed by
GitHub
Nov 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: base64 image (#3238)
* fix: base64 image * perf: quote qa
parent
cf1a90c5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
34 deletions
+51
-34
docSite/content/zh-cn/docs/development/upgrading/4814.md
+1
-0
packages/global/common/file/tools.ts
+5
-0
packages/service/core/chat/utils.ts
+5
-0
packages/service/core/workflow/dispatch/utils.ts
+5
-1
projects/app/src/pages/api/core/chat/chatTest.ts
+35
-33
No files found.
docSite/content/zh-cn/docs/development/upgrading/4814.md
View file @
a75036b6
...
@@ -49,3 +49,4 @@ weight: 810
...
@@ -49,3 +49,4 @@ weight: 810
17.
修复 - 反选知识库引用后可能会报错。
17.
修复 - 反选知识库引用后可能会报错。
18.
修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。
18.
修复 - 简易模式转工作流,不是使用最新编辑记录进行转移。
19.
修复 - 表单输入的说明文字不显示。
19.
修复 - 表单输入的说明文字不显示。
20.
修复 - API 无法使用 base64 图片。
packages/global/common/file/tools.ts
View file @
a75036b6
...
@@ -23,6 +23,11 @@ export const parseUrlToFileType = (url: string): UserChatItemValueItemType['file
...
@@ -23,6 +23,11 @@ export const parseUrlToFileType = (url: string): UserChatItemValueItemType['file
const
parseUrl
=
new
URL
(
url
,
'https://locaohost:3000'
);
const
parseUrl
=
new
URL
(
url
,
'https://locaohost:3000'
);
const
filename
=
(()
=>
{
const
filename
=
(()
=>
{
// Check base64 image
if
(
url
.
startsWith
(
'data:image/'
))
{
const
mime
=
url
.
split
(
','
)[
0
].
split
(
':'
)[
1
].
split
(
';'
)[
0
];
return
`image.
${
mime
.
split
(
'/'
)[
1
]}
`
;
}
// Old version file url: https://xxx.com/file/read?filename=xxx.pdf
// Old version file url: https://xxx.com/file/read?filename=xxx.pdf
const
filenameQuery
=
parseUrl
.
searchParams
.
get
(
'filename'
);
const
filenameQuery
=
parseUrl
.
searchParams
.
get
(
'filename'
);
if
(
filenameQuery
)
return
filenameQuery
;
if
(
filenameQuery
)
return
filenameQuery
;
...
...
packages/service/core/chat/utils.ts
View file @
a75036b6
...
@@ -118,6 +118,11 @@ export const loadRequestMessages = async ({
...
@@ -118,6 +118,11 @@ export const loadRequestMessages = async ({
return
item
.
image_url
.
url
;
return
item
.
image_url
.
url
;
})();
})();
// base64 image
if
(
imgUrl
.
startsWith
(
'data:image/'
))
{
return
item
;
}
try
{
try
{
// If imgUrl is a local path, load image from local, and set url to base64
// If imgUrl is a local path, load image from local, and set url to base64
if
(
imgUrl
.
startsWith
(
'/'
))
{
if
(
imgUrl
.
startsWith
(
'/'
))
{
...
...
packages/service/core/workflow/dispatch/utils.ts
View file @
a75036b6
...
@@ -129,7 +129,11 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
...
@@ -129,7 +129,11 @@ export const valueTypeFormat = (value: any, type?: WorkflowIOValueTypeEnum) => {
return
value
;
return
value
;
};
};
export
const
checkQuoteQAValue
=
(
quoteQA
:
SearchDataResponseItemType
[]
=
[])
=>
{
export
const
checkQuoteQAValue
=
(
quoteQA
?:
SearchDataResponseItemType
[])
=>
{
if
(
!
quoteQA
)
return
undefined
;
if
(
quoteQA
.
length
===
0
)
{
return
[];
}
if
(
quoteQA
.
some
((
item
)
=>
!
item
.
q
||
!
item
.
datasetId
))
{
if
(
quoteQA
.
some
((
item
)
=>
!
item
.
q
||
!
item
.
datasetId
))
{
return
undefined
;
return
undefined
;
}
}
...
...
projects/app/src/pages/api/core/chat/chatTest.ts
View file @
a75036b6
...
@@ -199,42 +199,44 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -199,42 +199,44 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
});
});
// save chat
// save chat
const
isInteractiveRequest
=
!!
getLastInteractiveValue
(
histories
);
if
(
!
res
.
closed
)
{
const
{
text
:
userInteractiveVal
}
=
chatValue2RuntimePrompt
(
userQuestion
.
value
);
const
isInteractiveRequest
=
!!
getLastInteractiveValue
(
histories
);
const
{
text
:
userInteractiveVal
}
=
chatValue2RuntimePrompt
(
userQuestion
.
value
);
const
newTitle
=
isPlugin
const
newTitle
=
isPlugin
?
variables
.
cTime
??
getSystemTime
(
user
.
timezone
)
?
variables
.
cTime
??
getSystemTime
(
user
.
timezone
)
:
getChatTitleFromChatMessage
(
userQuestion
);
:
getChatTitleFromChatMessage
(
userQuestion
);
const
aiResponse
:
AIChatItemType
&
{
dataId
?:
string
}
=
{
const
aiResponse
:
AIChatItemType
&
{
dataId
?:
string
}
=
{
dataId
:
responseChatItemId
,
dataId
:
responseChatItemId
,
obj
:
ChatRoleEnum
.
AI
,
obj
:
ChatRoleEnum
.
AI
,
value
:
assistantResponses
,
value
:
assistantResponses
,
[
DispatchNodeResponseKeyEnum
.
nodeResponse
]:
flowResponses
[
DispatchNodeResponseKeyEnum
.
nodeResponse
]:
flowResponses
};
};
if
(
isInteractiveRequest
)
{
if
(
isInteractiveRequest
)
{
await
updateInteractiveChat
({
await
updateInteractiveChat
({
chatId
,
chatId
,
appId
:
app
.
_id
,
appId
:
app
.
_id
,
userInteractiveVal
,
userInteractiveVal
,
aiResponse
,
aiResponse
,
newVariables
newVariables
});
});
}
else
{
}
else
{
await
saveChat
({
await
saveChat
({
chatId
,
chatId
,
appId
:
app
.
_id
,
appId
:
app
.
_id
,
teamId
,
teamId
,
tmbId
:
tmbId
,
tmbId
:
tmbId
,
nodes
,
nodes
,
appChatConfig
:
chatConfig
,
appChatConfig
:
chatConfig
,
variables
:
newVariables
,
variables
:
newVariables
,
isUpdateUseTime
:
false
,
// owner update use time
isUpdateUseTime
:
false
,
// owner update use time
newTitle
,
newTitle
,
source
:
ChatSourceEnum
.
test
,
source
:
ChatSourceEnum
.
test
,
content
:
[
userQuestion
,
aiResponse
]
content
:
[
userQuestion
,
aiResponse
]
});
});
}
}
}
pushChatUsage
({
pushChatUsage
({
...
...
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