This commit is contained in:
Archer
2023-09-26 21:17:13 +08:00
committed by GitHub
parent a11e0bd9c3
commit 11848b8f44
34 changed files with 395 additions and 62 deletions

View File

@@ -5,6 +5,7 @@ import { ChatHistoryItemResType } from '@/types/chat';
import { formatPrice } from '@fastgpt/common/bill/index';
import { addLog } from '@/service/utils/tools';
import type { CreateBillType } from '@/types/common/bill';
import { defaultQGModel } from '@/pages/api/system/getInitData';
async function createBill(data: CreateBillType) {
try {
@@ -170,3 +171,22 @@ export const countModelPrice = ({ model, tokens }: { model: string; tokens: numb
if (!modelData) return 0;
return modelData.price * tokens;
};
export const pushQuestionGuideBill = ({ tokens, userId }: { tokens: number; userId: string }) => {
const qgModel = global.qgModel || defaultQGModel;
const total = qgModel.price * tokens;
createBill({
userId,
appName: '问题指引',
total,
source: BillSourceEnum.fastgpt,
list: [
{
moduleName: '问题指引',
amount: total,
model: qgModel.name,
tokenLen: tokens
}
]
});
};

View File

@@ -24,7 +24,7 @@ export const dispatchAnswer = (props: Record<string, any>): AnswerResponse => {
res,
event: detail ? sseResponseEventEnum.answer : undefined,
data: textAdaptGptResponse({
text: text.replace(/\\n/g, '\n')
text: text.replace?.(/\\n/g, '\n') || ''
})
});
}