diff --git a/src/constants/user.ts b/src/constants/user.ts index b158de9d1..7fe92b0b9 100644 --- a/src/constants/user.ts +++ b/src/constants/user.ts @@ -1,5 +1,16 @@ +export enum BillTypeEnum { + chat = 'chat', + splitData = 'splitData', + return = 'return' +} export enum PageTypeEnum { login = 'login', register = 'register', forgetPassword = 'forgetPassword' } + +export const BillTypeMap: Record<`${BillTypeEnum}`, string> = { + [BillTypeEnum.chat]: '对话', + [BillTypeEnum.splitData]: '文本拆分', + [BillTypeEnum.return]: '退款' +}; diff --git a/src/pages/api/chat/chatGpt.ts b/src/pages/api/chat/chatGpt.ts index 455395eb1..5a4c98e93 100644 --- a/src/pages/api/chat/chatGpt.ts +++ b/src/pages/api/chat/chatGpt.ts @@ -9,7 +9,7 @@ import { jsonRes } from '@/service/response'; import type { ModelSchema } from '@/types/mongoSchema'; import { PassThrough } from 'stream'; import { modelList } from '@/constants/model'; -import { pushBill } from '@/service/events/pushChatBill'; +import { pushChatBill } from '@/service/events/pushBill'; /* 发送提示词 */ export default async function handler(req: NextApiRequest, res: NextApiResponse) { @@ -91,7 +91,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) messages: formatPrompts, frequency_penalty: 0.5, // 越大,重复内容越少 presence_penalty: -0.5, // 越大,越容易出现新内容 - stream: true + stream: true, + stop: ['。!?.!.'] }, { timeout: 40000, @@ -149,7 +150,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const promptsContent = formatPrompts.map((item) => item.content).join(''); // 只有使用平台的 key 才计费 !userApiKey && - pushBill({ + pushChatBill({ modelName: model.service.modelName, userId, chatId, diff --git a/src/pages/api/chat/gpt3.ts b/src/pages/api/chat/gpt3.ts index 2744d64f3..286024368 100644 --- a/src/pages/api/chat/gpt3.ts +++ b/src/pages/api/chat/gpt3.ts @@ -8,7 +8,7 @@ import { jsonRes } from '@/service/response'; import type { ModelSchema } from '@/types/mongoSchema'; import { PassThrough } from 'stream'; import { modelList } from '@/constants/model'; -import { pushBill } from '@/service/events/pushChatBill'; +import { pushChatBill } from '@/service/events/pushBill'; /* 发送提示词 */ export default async function handler(req: NextApiRequest, res: NextApiResponse) { @@ -142,7 +142,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) // 只有使用平台的 key 才计费 !userApiKey && - pushBill({ + pushChatBill({ modelName: model.service.modelName, userId, chatId, diff --git a/src/pages/api/data/delData.ts b/src/pages/api/data/delData.ts index 5802b6c06..54337a7e3 100644 --- a/src/pages/api/data/delData.ts +++ b/src/pages/api/data/delData.ts @@ -1,7 +1,7 @@ // Next.js API route support: https://nextjs.org/docs/api-routes/introduction import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; -import { connectToDatabase, Data } from '@/service/mongo'; +import { connectToDatabase, Data, DataItem } from '@/service/mongo'; import { authToken } from '@/service/utils/tools'; import type { DataListItem } from '@/types/data'; import type { PagingData } from '@/types'; @@ -27,6 +27,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) isDeleted: true }); + // 改变 dataItem 状态为 0 + await DataItem.updateMany( + { + dataId + }, + { + status: 0 + } + ); + jsonRes>(res); } catch (err) { jsonRes(res, { diff --git a/src/pages/api/data/getDataItems.ts b/src/pages/api/data/getDataItems.ts index 37471732e..3f9b4ad78 100644 --- a/src/pages/api/data/getDataItems.ts +++ b/src/pages/api/data/getDataItems.ts @@ -26,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) dataId, status: 0 }) - .sort({ time: -1 }) // 按照创建时间倒序排列 + .sort({ _id: -1 }) // 按照创建时间倒序排列 .skip((pageNum - 1) * pageSize) .limit(pageSize); diff --git a/src/pages/api/data/getDataList.ts b/src/pages/api/data/getDataList.ts index 70452c9c1..0f483f0e9 100644 --- a/src/pages/api/data/getDataList.ts +++ b/src/pages/api/data/getDataList.ts @@ -58,7 +58,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) $filter: { input: '$items', as: 'item', - cond: { $eq: ['$$item.status', 1] } // 统计status为1的数量 + cond: { $ne: ['$$item.status', 0] } // 统计 status 不为0的数量 } } } diff --git a/src/pages/api/user/getBill.ts b/src/pages/api/user/getBill.ts index dec69fd28..ec591795e 100644 --- a/src/pages/api/user/getBill.ts +++ b/src/pages/api/user/getBill.ts @@ -25,7 +25,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const bills = await Bill.find({ userId }) - .sort({ time: -1 }) // 按照创建时间倒序排列 + .sort({ _id: -1 }) // 按照创建时间倒序排列 .skip((pageNum - 1) * pageSize) .limit(pageSize); diff --git a/src/pages/data/components/ImportDataModal.tsx b/src/pages/data/components/ImportDataModal.tsx index a15b37a87..10b9e627d 100644 --- a/src/pages/data/components/ImportDataModal.tsx +++ b/src/pages/data/components/ImportDataModal.tsx @@ -8,7 +8,6 @@ import { ModalBody, ModalCloseButton, Button, - Input, Box, Flex, Textarea @@ -21,10 +20,20 @@ import { postSplitData } from '@/api/data'; import { useMutation } from '@tanstack/react-query'; import { useToast } from '@/hooks/useToast'; import { useLoading } from '@/hooks/useLoading'; +import { formatPrice } from '@/utils/user'; +import { modelList, ChatModelNameEnum } from '@/constants/model'; const fileExtension = '.txt,.doc,.docx,.pdf,.md'; -const ImportDataModal = ({ dataId, onClose }: { dataId: string; onClose: () => void }) => { +const ImportDataModal = ({ + dataId, + onClose, + onSuccess +}: { + dataId: string; + onClose: () => void; + onSuccess: () => void; +}) => { const { openConfirm, ConfirmChild } = useConfirm({ content: '确认提交生成任务?该任务无法终止!' }); @@ -60,6 +69,7 @@ const ImportDataModal = ({ dataId, onClose }: { dataId: string; onClose: () => v status: 'success' }); onClose(); + onSuccess(); }, onError(err: any) { toast({ @@ -110,7 +120,16 @@ const ImportDataModal = ({ dataId, onClose }: { dataId: string; onClose: () => v - 导入数据,生成QA + + 导入数据,生成QA + + {formatPrice( + modelList.find((item) => item.model === ChatModelNameEnum.GPT35)?.price || 0, + 1000 + )} + 元/1K tokens + + @@ -132,13 +151,16 @@ const ImportDataModal = ({ dataId, onClose }: { dataId: string; onClose: () => v {activeTab === 'text' && ( -