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
91b02bbf
authored
May 03, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: img compress;perf: color.prompt response
parent
17a42ac0
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
12 deletions
+80
-12
src/components/Layout/navbarPhone.tsx
+1
-1
src/pages/api/chat/chat.ts
+0
-1
src/pages/chat/components/SlideBar.tsx
+1
-1
src/pages/chat/index.tsx
+1
-1
src/pages/model/detail/components/ModelEditForm.tsx
+11
-8
src/service/utils/chat/index.ts
+2
-0
src/utils/file.ts
+64
-0
No files found.
src/components/Layout/navbarPhone.tsx
View file @
91b02bbf
...
...
@@ -39,7 +39,7 @@ const NavbarPhone = ({
px=
{
7
}
>
<
Box
onClick=
{
onOpen
}
>
<
MyIcon
name=
"menu"
width=
{
'20px'
}
height=
{
'20px'
}
color=
{
'blackAlpha.
6
00'
}
></
MyIcon
>
<
MyIcon
name=
"menu"
width=
{
'20px'
}
height=
{
'20px'
}
color=
{
'blackAlpha.
7
00'
}
></
MyIcon
>
</
Box
>
</
Flex
>
<
Drawer
isOpen=
{
isOpen
}
placement=
"left"
size=
{
'xs'
}
onClose=
{
onClose
}
>
...
...
src/pages/api/chat/chat.ts
View file @
91b02bbf
...
...
@@ -83,7 +83,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
temperature
=
(
modelConstantsData
.
maxTemperature
*
(
model
.
chat
.
temperature
/
10
)).
toFixed
(
2
);
// console.log(filterPrompts);
// 发出请求
const
{
streamResponse
}
=
await
modelServiceToolMap
[
model
.
chat
.
chatModel
].
chatCompletion
({
...
...
src/pages/chat/components/SlideBar.tsx
View file @
91b02bbf
...
...
@@ -99,7 +99,7 @@ const SlideBar = ({
fetchMyModels
();
fetchCollectionModels
();
loadChatHistory
();
},
1
5
00
);
},
1
0
00
);
},
[
fetchCollectionModels
,
fetchMyModels
,
loadChatHistory
]);
/**
...
...
src/pages/chat/index.tsx
View file @
91b02bbf
...
...
@@ -432,7 +432,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
name=
{
'menu'
}
w=
{
'20px'
}
h=
{
'20px'
}
fill
=
{
useColorModeValue
(
'blackAlpha.700'
,
'white'
)
}
color
=
{
useColorModeValue
(
'blackAlpha.700'
,
'white'
)
}
/>
</
Box
>
<
Box
>
{
chatData
?.
name
}
</
Box
>
...
...
src/pages/model/detail/components/ModelEditForm.tsx
View file @
91b02bbf
...
...
@@ -26,7 +26,7 @@ import { formatPrice } from '@/utils/user';
import
{
useConfirm
}
from
'@/hooks/useConfirm'
;
import
{
useSelectFile
}
from
'@/hooks/useSelectFile'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
fileToBase64
}
from
'@/utils/file'
;
import
{
fileToBase64
,
compressImg
}
from
'@/utils/file'
;
const
ModelEditForm
=
({
formHooks
,
...
...
@@ -52,17 +52,19 @@ const ModelEditForm = ({
async
(
e
:
File
[])
=>
{
const
file
=
e
[
0
];
if
(
!
file
)
return
;
if
(
file
.
size
>
100
*
1024
)
{
return
toast
({
title
:
'头像需小于 100kb'
,
status
:
'warning'
try
{
const
base64
=
await
compressImg
({
file
});
}
const
base64
=
(
await
fileToBase64
(
file
))
as
string
;
setValue
(
'avatar'
,
base64
);
setRefresh
((
state
)
=>
!
state
);
}
catch
(
err
:
any
)
{
toast
({
title
:
typeof
err
===
'string'
?
err
:
'头像选择异常'
,
status
:
'warning'
});
}
},
[
setValue
,
toast
]
);
...
...
@@ -195,6 +197,7 @@ const ModelEditForm = ({
<
Flex
mt=
{
4
}
alignItems=
{
'center'
}
>
<
Box
mr=
{
4
}
>
知识库搜索
</
Box
>
<
Switch
isDisabled=
{
!
isOwner
}
isChecked=
{
getValues
(
'chat.useKb'
)
}
onChange=
{
()
=>
{
setValue
(
'chat.useKb'
,
!
getValues
(
'chat.useKb'
));
...
...
src/service/utils/chat/index.ts
View file @
91b02bbf
...
...
@@ -142,6 +142,7 @@ export const resStreamResponse = async ({
prompts
});
setTimeout
(()
=>
{
// push system prompt
!
stream
.
destroyed
&&
systemPrompt
&&
...
...
@@ -150,6 +151,7 @@ export const resStreamResponse = async ({
// close stream
!
stream
.
destroyed
&&
stream
.
push
(
null
);
stream
.
destroy
();
},
100
);
return
{
responseContent
,
totalTokens
,
finishMessages
};
};
src/utils/file.ts
View file @
91b02bbf
...
...
@@ -190,3 +190,67 @@ export const fileToBase64 = (file: File) => {
reader
.
onerror
=
(
error
)
=>
reject
(
error
);
});
};
/**
* compress image. response base64
* @param maxSize The max size of the compressed image
*/
export
const
compressImg
=
({
file
,
maxW
=
200
,
maxH
=
200
,
maxSize
=
1024
*
100
}:
{
file
:
File
;
maxW
?:
number
;
maxH
?:
number
;
maxSize
?:
number
;
})
=>
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
const
reader
=
new
FileReader
();
reader
.
readAsDataURL
(
file
);
reader
.
onload
=
()
=>
{
const
img
=
new
Image
();
// @ts-ignore
img
.
src
=
reader
.
result
;
img
.
onload
=
()
=>
{
let
width
=
img
.
width
;
let
height
=
img
.
height
;
if
(
width
>
height
)
{
if
(
width
>
maxW
)
{
height
*=
maxW
/
width
;
width
=
maxW
;
}
}
else
{
if
(
height
>
maxH
)
{
width
*=
maxH
/
height
;
height
=
maxH
;
}
}
const
canvas
=
document
.
createElement
(
'canvas'
);
canvas
.
width
=
width
;
canvas
.
height
=
height
;
const
ctx
=
canvas
.
getContext
(
'2d'
);
if
(
!
ctx
)
{
return
reject
(
'压缩图片异常'
);
}
ctx
.
drawImage
(
img
,
0
,
0
,
width
,
height
);
const
compressedDataUrl
=
canvas
.
toDataURL
(
file
.
type
,
1
);
// 移除 canvas 元素
canvas
.
remove
();
if
(
compressedDataUrl
.
length
>
maxSize
)
{
return
reject
(
'图片太大了'
);
}
resolve
(
compressedDataUrl
);
};
};
reader
.
onerror
=
(
err
)
=>
{
console
.
log
(
err
);
reject
(
'压缩图片异常'
);
};
});
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