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
56a0b48b
authored
Apr 13, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 文案;feat: 知识库模糊搜索
parent
ff24042d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
62 additions
and
43 deletions
+62
-43
src/api/model.ts
+1
-0
src/pages/api/model/data/getModelData.ts
+4
-4
src/pages/model/detail/components/ModelDataCard.tsx
+34
-6
src/pages/model/detail/components/ModelEditForm.tsx
+6
-6
src/pages/model/detail/index.tsx
+0
-11
src/pages/model/list/components/ModelTable.tsx
+14
-13
src/pages/number/components/BillTable.tsx
+1
-1
src/pages/number/components/PayRecordTable.tsx
+1
-1
src/service/events/pushBill.ts
+1
-1
No files found.
src/api/model.ts
View file @
56a0b48b
...
...
@@ -49,6 +49,7 @@ export const getModelTrainings = (id: string) =>
type
GetModelDataListProps
=
RequestPaging
&
{
modelId
:
string
;
searchText
:
string
;
};
/**
* 获取模型的知识库数据
...
...
src/pages/api/model/data/getModelData.ts
View file @
56a0b48b
...
...
@@ -4,20 +4,20 @@ import { connectToDatabase } from '@/service/mongo';
import
{
authToken
}
from
'@/service/utils/tools'
;
import
{
connectRedis
}
from
'@/service/redis'
;
import
{
VecModelDataIdx
}
from
'@/constants/redis'
;
import
{
SearchOptions
}
from
'redis'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
let
{
modelId
,
pageNum
=
1
,
pageSize
=
10
pageSize
=
10
,
searchText
=
''
}
=
req
.
query
as
{
modelId
:
string
;
pageNum
:
string
;
pageSize
:
string
;
searchText
:
string
;
};
const
{
authorization
}
=
req
.
headers
;
pageNum
=
+
pageNum
;
...
...
@@ -40,7 +40,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
// 从 redis 中获取数据
const
searchRes
=
await
redis
.
ft
.
search
(
VecModelDataIdx
,
`@modelId:{
${
modelId
}
} @userId:{
${
userId
}
}`
,
`@modelId:{
${
modelId
}
} @userId:{
${
userId
}
}
${
searchText
?
`*
${
searchText
}
*`
:
''
}
`
,
{
RETURN
:
[
'q'
,
'text'
,
'status'
],
LIMIT
:
{
...
...
src/pages/model/detail/components/ModelDataCard.tsx
View file @
56a0b48b
...
...
@@ -15,7 +15,8 @@ import {
Menu
,
MenuButton
,
MenuList
,
MenuItem
MenuItem
,
Input
}
from
'@chakra-ui/react'
;
import
type
{
ModelSchema
}
from
'@/types/mongoSchema'
;
import
type
{
RedisModelDataItemType
}
from
'@/types/redis'
;
...
...
@@ -40,9 +41,11 @@ const SelectFileModel = dynamic(() => import('./SelectFileModal'));
const
SelectUrlModel
=
dynamic
(()
=>
import
(
'./SelectUrlModal'
));
const
SelectCsvModal
=
dynamic
(()
=>
import
(
'./SelectCsvModal'
));
let
lastSearch
=
''
;
const
ModelDataCard
=
({
model
}:
{
model
:
ModelSchema
})
=>
{
const
{
Loading
,
setIsLoading
}
=
useLoading
();
const
[
searchText
,
setSearchText
]
=
useState
(
''
);
const
{
data
:
modelDataList
,
isLoading
,
...
...
@@ -54,7 +57,8 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
api
:
getModelDataList
,
pageSize
:
8
,
params
:
{
modelId
:
model
.
_id
modelId
:
model
.
_id
,
searchText
}
});
...
...
@@ -158,9 +162,33 @@ const ModelDataCard = ({ model }: { model: ModelSchema }) => {
</
MenuList
>
</
Menu
>
</
Flex
>
{
!!
(
splitDataLen
&&
splitDataLen
>
0
)
&&
(
<
Box
fontSize=
{
'xs'
}
>
{
splitDataLen
}
条数据正在拆分...
</
Box
>
)
}
<
Flex
mt=
{
4
}
>
{
/* 拆分数据提示 */
}
{
!!
(
splitDataLen
&&
splitDataLen
>
0
)
&&
(
<
Box
fontSize=
{
'xs'
}
>
{
splitDataLen
}
条数据正在拆分...
</
Box
>
)
}
<
Box
flex=
{
1
}
></
Box
>
<
Input
maxW=
{
'240px'
}
size=
{
'sm'
}
value=
{
searchText
}
placeholder=
"搜索相关问题和答案,回车确认"
onChange=
{
(
e
)
=>
setSearchText
(
e
.
target
.
value
)
}
onBlur=
{
()
=>
{
if
(
searchText
===
lastSearch
)
return
;
getData
(
1
);
lastSearch
=
searchText
;
}
}
onKeyDown=
{
(
e
)
=>
{
if
(
searchText
===
lastSearch
)
return
;
if
(
e
.
key
===
'Enter'
)
{
getData
(
1
);
lastSearch
=
searchText
;
}
}
}
/>
</
Flex
>
<
Box
mt=
{
4
}
>
<
TableContainer
minH=
{
'500px'
}
>
<
Table
variant=
{
'simple'
}
>
...
...
src/pages/model/detail/components/ModelEditForm.tsx
View file @
56a0b48b
...
...
@@ -54,20 +54,20 @@ const ModelEditForm = ({
})}
></
Input
>
</
Flex
>
<
Flex
alignItems=
{
'center'
}
mt=
{
4
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Box
flex=
{
'0 0 80px'
}
w=
{
0
}
>
modelId:
</
Box
>
<
Box
>
{
getValues
(
'_id'
)
}
</
Box
>
</
Flex
>
</
FormControl
>
<
Flex
alignItems=
{
'center'
}
mt=
{
4
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Box
flex=
{
'0 0 80px'
}
w=
{
0
}
>
底层模
型:
模型类
型:
</
Box
>
<
Box
>
{
getValues
(
'service.modelName'
)
}
</
Box
>
<
Box
>
{
modelList
.
find
((
item
)
=>
item
.
model
===
getValues
(
'service.modelName'
))?.
name
}
</
Box
>
</
Flex
>
<
Flex
alignItems=
{
'center'
}
mt=
{
4
}
>
<
Flex
alignItems=
{
'center'
}
mt=
{
5
}
>
<
Box
flex=
{
'0 0 80px'
}
w=
{
0
}
>
价格:
</
Box
>
...
...
@@ -80,7 +80,7 @@ const ModelEditForm = ({
</
Box
>
</
Flex
>
<
Flex
mt=
{
5
}
alignItems=
{
'center'
}
>
<
Box
flex=
{
'0 0
80px'
}
>
删除:
</
Box
>
<
Box
flex=
{
'0 0
150px'
}
>
删除模型和数据集
</
Box
>
<
Button
colorScheme=
{
'gray'
}
variant=
{
'outline'
}
...
...
src/pages/model/detail/index.tsx
View file @
56a0b48b
...
...
@@ -21,7 +21,6 @@ const ModelDetail = ({ modelId }: { modelId: string }) => {
const
{
isPc
,
media
}
=
useScreen
();
const
{
setLoading
}
=
useGlobalStore
();
// const SelectFileDom = useRef<HTMLInputElement>(null);
const
[
model
,
setModel
]
=
useState
<
ModelSchema
>
(
defaultModel
);
const
formHooks
=
useForm
<
ModelSchema
>
({
defaultValues
:
model
...
...
@@ -243,11 +242,6 @@ const ModelDetail = ({ modelId }: { modelId: string }) => {
<
Grid
mt=
{
5
}
gridTemplateColumns=
{
media
(
'1fr 1fr'
,
'1fr'
)
}
gridGap=
{
5
}
>
<
ModelEditForm
formHooks=
{
formHooks
}
handleDelModel=
{
handleDelModel
}
canTrain=
{
canTrain
}
/>
{
/* {canTrain && (
<Card p={4}>
<Training model={model} />
</Card>
)} */
}
{
canTrain
&&
model
.
_id
&&
(
<
Card
p=
{
4
}
...
...
@@ -263,11 +257,6 @@ const ModelDetail = ({ modelId }: { modelId: string }) => {
</
Card
>
)
}
</
Grid
>
{
/* 文件选择 */
}
{
/* <Box position={'absolute'} w={0} h={0} overflow={'hidden'}>
<input ref={SelectFileDom} type="file" accept=".jsonl" onChange={startTraining} />
</Box> */
}
</>
);
};
...
...
src/pages/model/list/components/ModelTable.tsx
View file @
56a0b48b
...
...
@@ -16,6 +16,7 @@ import { formatModelStatus } from '@/constants/model';
import
dayjs
from
'dayjs'
;
import
type
{
ModelSchema
}
from
'@/types/mongoSchema'
;
import
{
useRouter
}
from
'next/router'
;
import
{
modelList
}
from
'@/constants/model'
;
const
ModelTable
=
({
models
=
[],
...
...
@@ -32,6 +33,15 @@ const ModelTable = ({
dataIndex
:
'name'
},
{
title
:
'模型类型'
,
key
:
'service'
,
render
:
(
model
:
ModelSchema
)
=>
(
<
Box
fontWeight=
{
'bold'
}
whiteSpace=
{
'pre-wrap'
}
maxW=
{
'200px'
}
>
{
modelList
.
find
((
item
)
=>
item
.
model
===
model
.
service
.
modelName
)?.
name
}
</
Box
>
)
},
{
title
:
'最后更新时间'
,
key
:
'updateTime'
,
render
:
(
item
:
ModelSchema
)
=>
dayjs
(
item
.
updateTime
).
format
(
'YYYY-MM-DD HH:mm'
)
...
...
@@ -51,29 +61,20 @@ const ModelTable = ({
</
Tag
>
)
},
{
title
:
'AI模型'
,
key
:
'service'
,
render
:
(
item
:
ModelSchema
)
=>
(
<
Box
wordBreak=
{
'break-all'
}
whiteSpace=
{
'pre-wrap'
}
maxW=
{
'200px'
}
>
{
item
.
service
.
modelName
}
</
Box
>
)
},
{
title
:
'操作'
,
key
:
'control'
,
render
:
(
item
:
ModelSchema
)
=>
(
<>
<
Button
mr=
{
3
}
onClick=
{
()
=>
handlePreviewChat
(
item
.
_id
)
}
>
对话
</
Button
>
<
Button
colorScheme=
{
'gray'
}
mr=
{
3
}
variant=
{
'outline'
}
onClick=
{
()
=>
router
.
push
(
`/model/detail?modelId=${item._id}`
)
}
>
编辑
</
Button
>
<
Button
onClick=
{
()
=>
handlePreviewChat
(
item
.
_id
)
}
>
对话
</
Button
>
</>
)
}
...
...
src/pages/number/components/BillTable.tsx
View file @
56a0b48b
...
...
@@ -30,7 +30,7 @@ const BillTable = () => {
<
Th
>
类型
</
Th
>
<
Th
>
内容长度
</
Th
>
<
Th
>
Tokens 长度
</
Th
>
<
Th
>
消费
</
Th
>
<
Th
>
金额
</
Th
>
</
Tr
>
</
Thead
>
<
Tbody
fontSize=
{
'sm'
}
>
...
...
src/pages/number/components/PayRecordTable.tsx
View file @
56a0b48b
...
...
@@ -77,7 +77,7 @@ const PayRecordTable = () => {
<
Th
>
订单号
</
Th
>
<
Th
>
时间
</
Th
>
<
Th
>
金额
</
Th
>
<
Th
>
消费
</
Th
>
<
Th
>
状态
</
Th
>
<
Th
></
Th
>
</
Tr
>
</
Thead
>
...
...
src/service/events/pushBill.ts
View file @
56a0b48b
...
...
@@ -21,7 +21,7 @@ export const pushChatBill = async ({
try
{
// 计算 token 数量
const
tokens
=
Math
.
floor
(
encode
(
text
).
length
*
0.7
);
const
tokens
=
Math
.
floor
(
encode
(
text
).
length
*
0.7
5
);
console
.
log
(
`chat generate success. text len:
${
text
.
length
}
. token len:
${
tokens
}
`
);
...
...
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