This commit is contained in:
Archer
2023-11-15 21:35:50 +08:00
committed by GitHub
parent bfd8be5df0
commit cd3acb44ab
39 changed files with 457 additions and 160 deletions

View File

@@ -109,6 +109,7 @@ export async function generateQA(): Promise<any> {
try {
const startTime = Date.now();
const model = data.model ?? global.qaModels[0].model;
// request LLM to get QA
const messages: ChatMessageItemType[] = [
@@ -122,9 +123,10 @@ export async function generateQA(): Promise<any> {
})
}
];
const ai = getAIApi(undefined, 480000);
const ai = getAIApi(undefined, 600000);
const chatResponse = await ai.chat.completions.create({
model: global.qaModels[0].model,
model,
temperature: 0.01,
messages,
stream: false
@@ -147,8 +149,11 @@ export async function generateQA(): Promise<any> {
// delete data from training
await MongoDatasetTraining.findByIdAndDelete(data._id);
console.log(`split result length: `, qaArr.length);
console.log('生成QA成功time:', `${(Date.now() - startTime) / 1000}s`);
addLog.info(`QA Training Finish`, {
time: `${(Date.now() - startTime) / 1000}s`,
splitLength: qaArr.length,
usage: chatResponse.usage
});
// add bill
if (qaArr.length > 0) {
@@ -156,7 +161,8 @@ export async function generateQA(): Promise<any> {
teamId: data.teamId,
tmbId: data.tmbId,
totalTokens,
billId: data.billId
billId: data.billId,
model
});
} else {
addLog.info(`QA result 0:`, { answer });

View File

@@ -1,5 +1,5 @@
import { BillSourceEnum } from '@fastgpt/global/support/wallet/bill/constants';
import { getAudioSpeechModel } from '@/service/core/ai/model';
import { getAudioSpeechModel, getQAModel } from '@/service/core/ai/model';
import type { ChatHistoryItemResType } from '@fastgpt/global/core/chat/api.d';
import { formatPrice } from '@fastgpt/global/support/wallet/bill/tools';
import { addLog } from '@fastgpt/service/common/mongo/controller';
@@ -9,10 +9,16 @@ import { POST } from '@fastgpt/service/common/api/plusRequest';
export function createBill(data: CreateBillProps) {
if (!global.systemEnv.pluginBaseUrl) return;
if (data.total === 0) {
addLog.info('0 Bill', data);
}
POST('/support/wallet/bill/createBill', data);
}
export function concatBill(data: ConcatBillProps) {
if (!global.systemEnv.pluginBaseUrl) return;
if (data.total === 0) {
addLog.info('0 Bill', data);
}
POST('/support/wallet/bill/concatBill', data);
}
@@ -59,18 +65,18 @@ export const pushChatBill = ({
export const pushQABill = async ({
teamId,
tmbId,
model,
totalTokens,
billId
}: {
teamId: string;
tmbId: string;
model: string;
totalTokens: number;
billId: string;
}) => {
addLog.info('splitData generate success', { totalTokens });
// 获取模型单价格
const unitPrice = global.qaModels?.[0]?.price || 3;
const unitPrice = getQAModel(model).price;
// 计算价格
const total = unitPrice * totalTokens;