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
7a76f541
authored
Jul 19, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: bill, app detail
parent
58cbf10c
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
63 additions
and
41 deletions
+63
-41
client/src/components/ChatBox/index.tsx
+8
-6
client/src/constants/model.ts
+1
-1
client/src/pages/api/app/modules/kb/search.ts
+6
-2
client/src/pages/api/chat/shareChat/list.ts
+1
-1
client/src/pages/api/openapi/v1/chat/completions.ts
+2
-1
client/src/pages/app/detail/components/Settings.tsx
+3
-12
client/src/pages/app/detail/components/Share.tsx
+3
-8
client/src/pages/app/detail/index.tsx
+17
-1
client/src/service/events/pushBill.ts
+16
-6
client/src/service/models/shareChat.ts
+1
-1
client/src/service/utils/tools.ts
+4
-1
client/src/types/mongoSchema.d.ts
+1
-1
No files found.
client/src/components/ChatBox/index.tsx
View file @
7a76f541
...
@@ -27,19 +27,20 @@ import { useMarkdown } from '@/hooks/useMarkdown';
...
@@ -27,19 +27,20 @@ import { useMarkdown } from '@/hooks/useMarkdown';
import
{
AppModuleItemType
,
VariableItemType
}
from
'@/types/app'
;
import
{
AppModuleItemType
,
VariableItemType
}
from
'@/types/app'
;
import
{
SystemInputEnum
,
VariableInputEnum
}
from
'@/constants/app'
;
import
{
SystemInputEnum
,
VariableInputEnum
}
from
'@/constants/app'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
useForm
}
from
'react-hook-form'
;
import
MySelect
from
'@/components/Select'
;
import
{
MessageItemType
}
from
'@/pages/api/openapi/v1/chat/completions'
;
import
{
MessageItemType
}
from
'@/pages/api/openapi/v1/chat/completions'
;
import
MyTooltip
from
'../MyTooltip'
;
import
{
fileDownload
}
from
'@/utils/file'
;
import
{
fileDownload
}
from
'@/utils/file'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useGlobalStore
}
from
'@/store/global'
;
import
dynamic
from
'next/dynamic'
;
import
dynamic
from
'next/dynamic'
;
const
QuoteModal
=
dynamic
(()
=>
import
(
'./QuoteModal'
));
const
QuoteModal
=
dynamic
(()
=>
import
(
'./QuoteModal'
));
import
styles
from
'./index.module.scss'
;
import
{
QuoteItemType
}
from
'@/pages/api/app/modules/kb/search'
;
import
{
QuoteItemType
}
from
'@/pages/api/app/modules/kb/search'
;
import
{
FlowModuleTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowModuleTypeEnum
}
from
'@/constants/flow'
;
import
MyTooltip
from
'../MyTooltip'
;
import
MySelect
from
'@/components/Select'
;
import
styles
from
'./index.module.scss'
;
const
textareaMinH
=
'22px'
;
const
textareaMinH
=
'22px'
;
export
type
StartChatFnProps
=
{
export
type
StartChatFnProps
=
{
...
@@ -139,6 +140,7 @@ const ChatBox = (
...
@@ -139,6 +140,7 @@ const ChatBox = (
const
{
copyData
}
=
useCopyData
();
const
{
copyData
}
=
useCopyData
();
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
const
{
userInfo
}
=
useUserStore
();
const
{
userInfo
}
=
useUserStore
();
const
{
isPc
}
=
useGlobalStore
();
const
TextareaDom
=
useRef
<
HTMLTextAreaElement
>
(
null
);
const
TextareaDom
=
useRef
<
HTMLTextAreaElement
>
(
null
);
const
controller
=
useRef
(
new
AbortController
());
const
controller
=
useRef
(
new
AbortController
());
...
@@ -312,7 +314,7 @@ const ChatBox = (
...
@@ -312,7 +314,7 @@ const ChatBox = (
setTimeout
(()
=>
{
setTimeout
(()
=>
{
generatingScroll
();
generatingScroll
();
TextareaDom
.
current
?.
focus
();
isPc
&&
TextareaDom
.
current
?.
focus
();
},
100
);
},
100
);
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
toast
({
toast
({
...
@@ -342,13 +344,13 @@ const ChatBox = (
...
@@ -342,13 +344,13 @@ const ChatBox = (
[
[
isChatting
,
isChatting
,
chatHistory
,
chatHistory
,
setChatHistory
,
resetInputVal
,
resetInputVal
,
toast
,
toast
,
scrollToBottom
,
scrollToBottom
,
onStartChat
,
onStartChat
,
generatingMessage
,
generatingMessage
,
generatingScroll
generatingScroll
,
isPc
]
]
);
);
...
...
client/src/constants/model.ts
View file @
7a76f541
...
@@ -11,7 +11,7 @@ export enum OpenAiChatEnum {
...
@@ -11,7 +11,7 @@ export enum OpenAiChatEnum {
export
const
defaultApp
:
AppSchema
=
{
export
const
defaultApp
:
AppSchema
=
{
_id
:
''
,
_id
:
''
,
userId
:
'userId'
,
userId
:
'userId'
,
name
:
'模型
名称
'
,
name
:
'模型
加载中
'
,
avatar
:
'/icon/logo.png'
,
avatar
:
'/icon/logo.png'
,
intro
:
''
,
intro
:
''
,
updateTime
:
Date
.
now
(),
updateTime
:
Date
.
now
(),
...
...
client/src/pages/api/app/modules/kb/search.ts
View file @
7a76f541
...
@@ -39,8 +39,12 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -39,8 +39,12 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
const
{
kb_ids
=
[],
userChatInput
}
=
req
.
body
as
Props
;
const
{
kb_ids
=
[],
userChatInput
}
=
req
.
body
as
Props
;
if
(
!
userChatInput
||
!
Array
.
isArray
(
kb_ids
))
{
if
(
!
userChatInput
)
{
throw
new
Error
(
'params is error'
);
throw
new
Error
(
'用户输入为空'
);
}
if
(
!
Array
.
isArray
(
kb_ids
)
||
kb_ids
.
length
===
0
)
{
throw
new
Error
(
'没有选择知识库'
);
}
}
const
result
=
await
kbSearch
({
const
result
=
await
kbSearch
({
...
...
client/src/pages/api/chat/shareChat/list.ts
View file @
7a76f541
...
@@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
_id
:
item
.
_id
,
_id
:
item
.
_id
,
shareId
:
item
.
shareId
,
shareId
:
item
.
shareId
,
name
:
item
.
name
,
name
:
item
.
name
,
to
kens
:
item
.
tokens
,
to
tal
:
item
.
total
,
maxContext
:
item
.
maxContext
,
maxContext
:
item
.
maxContext
,
lastTime
:
item
.
lastTime
lastTime
:
item
.
lastTime
}))
}))
...
...
client/src/pages/api/openapi/v1/chat/completions.ts
View file @
7a76f541
...
@@ -188,7 +188,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -188,7 +188,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
// bill
// bill
finishTaskBill
({
finishTaskBill
({
billId
billId
,
shareId
});
});
}
catch
(
err
:
any
)
{
}
catch
(
err
:
any
)
{
delTaskBill
(
billId
);
delTaskBill
(
billId
);
...
...
client/src/pages/app/detail/components/Settings.tsx
View file @
7a76f541
...
@@ -51,17 +51,8 @@ const Settings = ({ appId }: { appId: string }) => {
...
@@ -51,17 +51,8 @@ const Settings = ({ appId }: { appId: string }) => {
},
[
appDetail
,
setIsLoading
,
toast
,
router
]);
},
[
appDetail
,
setIsLoading
,
toast
,
router
]);
// load app data
// load app data
const
{
isLoading
,
refetch
}
=
useQuery
([
appId
],
()
=>
loadAppDetail
(
appId
,
true
),
{
const
{
refetch
}
=
useQuery
([
appId
],
()
=>
loadAppDetail
(
appId
,
true
),
{
onError
(
err
:
any
)
{
enabled
:
false
toast
({
title
:
err
?.
message
||
'获取应用异常'
,
status
:
'error'
});
router
.
replace
(
'/app/list'
);
},
onSettled
()
{
router
.
prefetch
(
`/chat?appId=
${
appId
}
`
);
}
});
});
return
(
return
(
...
@@ -168,7 +159,7 @@ const Settings = ({ appId }: { appId: string }) => {
...
@@ -168,7 +159,7 @@ const Settings = ({ appId }: { appId: string }) => {
)
}
)
}
<
ConfirmChild
/>
<
ConfirmChild
/>
<
Loading
loading=
{
isLoading
}
fixed=
{
false
}
/>
<
Loading
fixed=
{
false
}
/>
</
Flex
>
</
Flex
>
);
);
};
};
...
...
client/src/pages/app/detail/components/Share.tsx
View file @
7a76f541
...
@@ -38,6 +38,7 @@ import { defaultShareChat } from '@/constants/model';
...
@@ -38,6 +38,7 @@ import { defaultShareChat } from '@/constants/model';
import
type
{
ShareChatEditType
}
from
'@/types/app'
;
import
type
{
ShareChatEditType
}
from
'@/types/app'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
{
useRequest
}
from
'@/hooks/useRequest'
;
import
{
useRequest
}
from
'@/hooks/useRequest'
;
import
{
formatPrice
}
from
'@/utils/user'
;
const
Share
=
({
appId
}:
{
appId
:
string
})
=>
{
const
Share
=
({
appId
}:
{
appId
:
string
})
=>
{
const
{
toast
}
=
useToast
();
const
{
toast
}
=
useToast
();
...
@@ -82,12 +83,6 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -82,12 +83,6 @@ const Share = ({ appId }: { appId: string }) => {
}
}
});
});
// format share used token
const
formatTokens
=
(
tokens
:
number
)
=>
{
if
(
tokens
<
10000
)
return
tokens
;
return
`
${(
tokens
/
10000
).
toFixed
(
2
)}
万`
;
};
return
(
return
(
<
Box
position=
{
'relative'
}
pt=
{
[
0
,
5
,
8
]
}
px=
{
[
5
,
8
]
}
minH=
{
'50vh'
}
>
<
Box
position=
{
'relative'
}
pt=
{
[
0
,
5
,
8
]
}
px=
{
[
5
,
8
]
}
minH=
{
'50vh'
}
>
<
Flex
justifyContent=
{
'space-between'
}
>
<
Flex
justifyContent=
{
'space-between'
}
>
...
@@ -118,7 +113,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -118,7 +113,7 @@ const Share = ({ appId }: { appId: string }) => {
<
Tr
>
<
Tr
>
<
Th
>
名称
</
Th
>
<
Th
>
名称
</
Th
>
<
Th
>
最大上下文
</
Th
>
<
Th
>
最大上下文
</
Th
>
<
Th
>
tokens
消耗
</
Th
>
<
Th
>
金额
消耗
</
Th
>
<
Th
>
最后使用时间
</
Th
>
<
Th
>
最后使用时间
</
Th
>
<
Th
>
操作
</
Th
>
<
Th
>
操作
</
Th
>
</
Tr
>
</
Tr
>
...
@@ -128,7 +123,7 @@ const Share = ({ appId }: { appId: string }) => {
...
@@ -128,7 +123,7 @@ const Share = ({ appId }: { appId: string }) => {
<
Tr
key=
{
item
.
_id
}
>
<
Tr
key=
{
item
.
_id
}
>
<
Td
>
{
item
.
name
}
</
Td
>
<
Td
>
{
item
.
name
}
</
Td
>
<
Td
>
{
item
.
maxContext
}
</
Td
>
<
Td
>
{
item
.
maxContext
}
</
Td
>
<
Td
>
{
format
Tokens
(
item
.
tokens
)
}
</
Td
>
<
Td
>
{
format
Price
(
item
.
total
)
}
元
</
Td
>
<
Td
>
{
item
.
lastTime
?
formatTimeToChatTime
(
item
.
lastTime
)
:
'未使用'
}
</
Td
>
<
Td
>
{
item
.
lastTime
?
formatTimeToChatTime
(
item
.
lastTime
)
:
'未使用'
}
</
Td
>
<
Td
>
<
Td
>
<
Flex
>
<
Flex
>
...
...
client/src/pages/app/detail/index.tsx
View file @
7a76f541
...
@@ -4,6 +4,8 @@ import { Box, Flex, IconButton, useTheme } from '@chakra-ui/react';
...
@@ -4,6 +4,8 @@ import { Box, Flex, IconButton, useTheme } from '@chakra-ui/react';
import
{
useUserStore
}
from
'@/store/user'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
dynamic
from
'next/dynamic'
;
import
dynamic
from
'next/dynamic'
;
import
{
defaultApp
}
from
'@/constants/model'
;
import
{
defaultApp
}
from
'@/constants/model'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
Tabs
from
'@/components/Tabs'
;
import
Tabs
from
'@/components/Tabs'
;
import
SideTabs
from
'@/components/SideTabs'
;
import
SideTabs
from
'@/components/SideTabs'
;
...
@@ -28,8 +30,9 @@ enum TabEnum {
...
@@ -28,8 +30,9 @@ enum TabEnum {
const
AppDetail
=
({
currentTab
}:
{
currentTab
:
`
${
TabEnum
}
`
})
=>
{
const
AppDetail
=
({
currentTab
}:
{
currentTab
:
`
${
TabEnum
}
`
})
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
theme
=
useTheme
();
const
theme
=
useTheme
();
const
{
toast
}
=
useToast
();
const
{
appId
}
=
router
.
query
as
{
appId
:
string
};
const
{
appId
}
=
router
.
query
as
{
appId
:
string
};
const
{
appDetail
=
defaultApp
,
clearAppModules
}
=
useUserStore
();
const
{
appDetail
=
defaultApp
,
loadAppDetail
,
clearAppModules
}
=
useUserStore
();
const
setCurrentTab
=
useCallback
(
const
setCurrentTab
=
useCallback
(
(
tab
:
`
${
TabEnum
}
`
)
=>
{
(
tab
:
`
${
TabEnum
}
`
)
=>
{
...
@@ -65,6 +68,19 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -65,6 +68,19 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
};
};
},
[]);
},
[]);
useQuery
([
appId
],
()
=>
loadAppDetail
(
appId
,
true
),
{
onError
(
err
:
any
)
{
toast
({
title
:
err
?.
message
||
'获取应用异常'
,
status
:
'error'
});
router
.
replace
(
'/app/list'
);
},
onSettled
()
{
router
.
prefetch
(
`/chat?appId=
${
appId
}
`
);
}
});
return
(
return
(
<
PageContainer
>
<
PageContainer
>
<
Flex
flexDirection=
{
[
'column'
,
'row'
]
}
h=
{
'100%'
}
>
<
Flex
flexDirection=
{
[
'column'
,
'row'
]
}
h=
{
'100%'
}
>
...
...
client/src/service/events/pushBill.ts
View file @
7a76f541
...
@@ -47,7 +47,7 @@ export const pushTaskBillListItem = async ({
...
@@ -47,7 +47,7 @@ export const pushTaskBillListItem = async ({
});
});
}
catch
(
error
)
{}
}
catch
(
error
)
{}
};
};
export
const
finishTaskBill
=
async
({
billId
}:
{
billId
:
string
})
=>
{
export
const
finishTaskBill
=
async
({
billId
,
shareId
}:
{
billId
:
string
;
shareId
?
:
string
})
=>
{
try
{
try
{
// update bill
// update bill
const
res
=
await
Bill
.
findByIdAndUpdate
(
billId
,
[
const
res
=
await
Bill
.
findByIdAndUpdate
(
billId
,
[
...
@@ -63,6 +63,13 @@ export const finishTaskBill = async ({ billId }: { billId: string }) => {
...
@@ -63,6 +63,13 @@ export const finishTaskBill = async ({ billId }: { billId: string }) => {
if
(
!
res
)
return
;
if
(
!
res
)
return
;
const
total
=
res
.
list
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
amount
,
0
)
||
0
;
const
total
=
res
.
list
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
amount
,
0
)
||
0
;
if
(
shareId
)
{
updateShareChatBill
({
shareId
,
total
});
}
console
.
log
(
'finish bill:'
,
formatPrice
(
total
));
console
.
log
(
'finish bill:'
,
formatPrice
(
total
));
// 账号扣费
// 账号扣费
...
@@ -85,16 +92,19 @@ export const delTaskBill = async (billId?: string) => {
...
@@ -85,16 +92,19 @@ export const delTaskBill = async (billId?: string) => {
export
const
updateShareChatBill
=
async
({
export
const
updateShareChatBill
=
async
({
shareId
,
shareId
,
to
kens
to
tal
}:
{
}:
{
shareId
:
string
;
shareId
:
string
;
to
kens
:
number
;
to
tal
:
number
;
})
=>
{
})
=>
{
try
{
try
{
await
ShareChat
.
findByIdAndUpdate
(
shareId
,
{
await
ShareChat
.
findOneAndUpdate
(
$inc
:
{
tokens
},
{
shareId
},
{
$inc
:
{
total
},
lastTime
:
new
Date
()
lastTime
:
new
Date
()
});
}
);
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'update shareChat error'
,
error
);
console
.
log
(
'update shareChat error'
,
error
);
}
}
...
...
client/src/service/models/shareChat.ts
View file @
7a76f541
...
@@ -20,7 +20,7 @@ const ShareChatSchema = new Schema({
...
@@ -20,7 +20,7 @@ const ShareChatSchema = new Schema({
type
:
String
,
type
:
String
,
required
:
true
required
:
true
},
},
to
kens
:
{
to
tal
:
{
type
:
Number
,
type
:
Number
,
default
:
0
default
:
0
},
},
...
...
client/src/service/utils/tools.ts
View file @
7a76f541
...
@@ -25,7 +25,10 @@ export const generateToken = (userId: string) => {
...
@@ -25,7 +25,10 @@ export const generateToken = (userId: string) => {
/* set cookie */
/* set cookie */
export
const
setCookie
=
(
res
:
NextApiResponse
,
userId
:
string
)
=>
{
export
const
setCookie
=
(
res
:
NextApiResponse
,
userId
:
string
)
=>
{
res
.
setHeader
(
'Set-Cookie'
,
`token=
${
generateToken
(
userId
)}
; Path=/; HttpOnly; Max-Age=604800`
);
res
.
setHeader
(
'Set-Cookie'
,
`token=
${
generateToken
(
userId
)}
; Path=/; HttpOnly; Max-Age=604800; Samesite=None; Secure;`
);
};
};
/* clear cookie */
/* clear cookie */
export
const
clearCookie
=
(
res
:
NextApiResponse
)
=>
{
export
const
clearCookie
=
(
res
:
NextApiResponse
)
=>
{
...
...
client/src/types/mongoSchema.d.ts
View file @
7a76f541
...
@@ -137,7 +137,7 @@ export interface ShareChatSchema {
...
@@ -137,7 +137,7 @@ export interface ShareChatSchema {
userId
:
string
;
userId
:
string
;
appId
:
string
;
appId
:
string
;
name
:
string
;
name
:
string
;
to
kens
:
number
;
to
tal
:
number
;
maxContext
:
number
;
maxContext
:
number
;
lastTime
:
Date
;
lastTime
:
Date
;
}
}
...
...
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