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
16018a7e
authored
Jun 06, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: mongo index;fix: loading status and abort chat, system prompt empty
parent
707be336
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
21 deletions
+35
-21
src/api/fetch.ts
+1
-1
src/pages/api/model/create.ts
+1
-1
src/pages/api/model/share/getModels.ts
+1
-1
src/pages/api/user/getBill.ts
+10
-10
src/pages/kb/components/KbList.tsx
+3
-3
src/pages/model/components/ModelList.tsx
+5
-5
src/service/models/bill.ts
+7
-0
src/service/models/model.ts
+7
-0
No files found.
src/api/fetch.ts
View file @
16018a7e
...
...
@@ -50,7 +50,7 @@ export const streamFetch = ({ url, data, onMessage, abortSignal }: StreamFetchPr
read
();
}
catch
(
err
:
any
)
{
if
(
err
?.
message
===
'The user aborted a request.'
)
{
return
resolve
({
responseText
,
newChatId
,
quoteLen
,
systemPrompt
:
''
});
return
resolve
({
responseText
,
newChatId
,
quoteLen
,
systemPrompt
});
}
reject
(
typeof
err
===
'string'
?
err
:
err
?.
message
||
'请求异常'
);
}
...
...
src/pages/api/model/create.ts
View file @
16018a7e
...
...
@@ -26,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
userId
});
if
(
authCount
>=
30
)
{
throw
new
Error
(
'上限 30 个
助手
'
);
throw
new
Error
(
'上限 30 个
应用
'
);
}
// 创建模型
...
...
src/pages/api/model/share/getModels.ts
View file @
16018a7e
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
connectToDatabase
,
Collection
,
Model
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Model
}
from
'@/service/mongo'
;
import
type
{
PagingData
}
from
'@/types'
;
import
type
{
ShareModelItem
}
from
'@/types/model'
;
import
{
parseCookie
}
from
'@/service/utils/auth'
;
...
...
src/pages/api/user/getBill.ts
View file @
16018a7e
...
...
@@ -16,18 +16,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
await
connectToDatabase
();
// 根据 id 获取用户账单
const
bills
=
await
Bill
.
find
({
const
where
=
{
userId
})
.
sort
({
_id
:
-
1
})
// 按照创建时间倒序排列
.
skip
((
pageNum
-
1
)
*
pageSize
)
.
limit
(
pageSize
);
};
// 获取total
const
total
=
await
Bill
.
countDocuments
({
userId
});
// get bill record and total by record
const
[
bills
,
total
]
=
await
Promise
.
all
([
Bill
.
find
(
where
)
.
sort
({
time
:
-
1
})
// 按照创建时间倒序排列
.
skip
((
pageNum
-
1
)
*
pageSize
)
.
limit
(
pageSize
),
Bill
.
countDocuments
(
where
)
]);
jsonRes
(
res
,
{
data
:
{
...
...
src/pages/kb/components/KbList.tsx
View file @
16018a7e
...
...
@@ -24,7 +24,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
);
/* 加载模型 */
const
{
is
Load
ing
}
=
useQuery
([
'loadModels'
],
()
=>
loadKbList
(
false
));
const
{
is
Fetch
ing
}
=
useQuery
([
'loadModels'
],
()
=>
loadKbList
(
false
));
const
handleCreateModel
=
useCallback
(
async
()
=>
{
setIsLoading
(
true
);
...
...
@@ -133,7 +133,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
</
Flex
>
))
}
{
!
is
Load
ing
&&
myKbList
.
length
===
0
&&
(
{
!
is
Fetch
ing
&&
myKbList
.
length
===
0
&&
(
<
Flex
h=
{
'100%'
}
flexDirection=
{
'column'
}
alignItems=
{
'center'
}
pt=
{
'30vh'
}
>
<
MyIcon
name=
"empty"
w=
{
'48px'
}
h=
{
'48px'
}
color=
{
'transparent'
}
/>
<
Box
mt=
{
2
}
color=
{
'myGray.500'
}
>
...
...
@@ -142,7 +142,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
</
Flex
>
)
}
</
Box
>
<
Loading
loading=
{
is
Load
ing
}
fixed=
{
false
}
/>
<
Loading
loading=
{
is
Fetch
ing
}
fixed=
{
false
}
/>
</
Flex
>
);
};
...
...
src/pages/model/components/ModelList.tsx
View file @
16018a7e
...
...
@@ -19,7 +19,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
const
[
searchText
,
setSearchText
]
=
useState
(
''
);
/* 加载模型 */
const
{
is
Load
ing
}
=
useQuery
([
'loadModels'
],
()
=>
loadMyModels
(
false
));
const
{
is
Fetch
ing
}
=
useQuery
([
'loadModels'
],
()
=>
loadMyModels
(
false
));
const
onclickCreateModel
=
useCallback
(
async
()
=>
{
setIsLoading
(
true
);
...
...
@@ -77,7 +77,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
<
Flex
flex=
{
1
}
mr=
{
2
}
position=
{
'relative'
}
alignItems=
{
'center'
}
>
<
Input
h=
{
'32px'
}
placeholder=
"搜索 AI
助手
"
placeholder=
"搜索 AI
应用
"
value=
{
searchText
}
onChange=
{
(
e
)
=>
setSearchText
(
e
.
target
.
value
)
}
/>
...
...
@@ -149,16 +149,16 @@ const ModelList = ({ modelId }: { modelId: string }) => {
</
Box
>
))
}
{
!
is
Load
ing
&&
totalModels
===
0
&&
(
{
!
is
Fetch
ing
&&
totalModels
===
0
&&
(
<
Flex
h=
{
'100%'
}
flexDirection=
{
'column'
}
alignItems=
{
'center'
}
pt=
{
'30vh'
}
>
<
MyIcon
name=
"empty"
w=
{
'48px'
}
h=
{
'48px'
}
color=
{
'transparent'
}
/>
<
Box
mt=
{
2
}
color=
{
'myGray.500'
}
>
还没有 AI
助手
~
还没有 AI
应用
~
</
Box
>
</
Flex
>
)
}
</
Box
>
<
Loading
loading=
{
is
Load
ing
}
fixed=
{
false
}
/>
<
Loading
loading=
{
is
Fetch
ing
}
fixed=
{
false
}
/>
</
Flex
>
);
};
...
...
src/service/models/bill.ts
View file @
16018a7e
...
...
@@ -43,4 +43,11 @@ const BillSchema = new Schema({
}
});
try
{
BillSchema
.
index
({
time
:
-
1
});
BillSchema
.
index
({
userId
:
1
});
}
catch
(
error
)
{
error
;
}
export
const
Bill
:
Model
<
BillType
>
=
models
[
'bill'
]
||
model
(
'bill'
,
BillSchema
);
src/service/models/model.ts
View file @
16018a7e
...
...
@@ -82,4 +82,11 @@ const ModelSchema = new Schema({
}
});
try
{
ModelSchema
.
index
({
updateTime
:
-
1
});
ModelSchema
.
index
({
'share.collection'
:
-
1
});
}
catch
(
error
)
{
error
;
}
export
const
Model
:
MongoModel
<
ModelType
>
=
models
[
'model'
]
||
model
(
'model'
,
ModelSchema
);
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