mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-01 20:27:45 +00:00
perf: bill
This commit is contained in:
@@ -8,6 +8,7 @@ import { ChatRoleEnum } from '@/constants/chat';
|
||||
import { getOpenAIApi, axiosConfig } from '@/service/ai/openai';
|
||||
import type { RecognizeIntentionAgentItemType } from '@/types/app';
|
||||
import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill';
|
||||
import { getModel } from '@/service/utils/data';
|
||||
|
||||
export type Props = {
|
||||
systemPrompt?: string;
|
||||
@@ -115,7 +116,7 @@ export async function classifyQuestion({
|
||||
billId,
|
||||
moduleName: 'Recognize Intention',
|
||||
amount: countModelPrice({ model: agentModel, tokens: totalTokens }),
|
||||
model: agentModel,
|
||||
model: getModel(agentModel)?.name,
|
||||
tokenLen: totalTokens
|
||||
});
|
||||
|
||||
|
@@ -31,21 +31,10 @@ export type Response = { [SpecificInputEnum.answerText]: string; totalTokens: nu
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
let { model, temperature = 0, stream } = req.body as Props;
|
||||
try {
|
||||
// temperature adapt
|
||||
const modelConstantsData = getChatModel(model);
|
||||
|
||||
if (!modelConstantsData) {
|
||||
throw new Error('The chat model is undefined');
|
||||
}
|
||||
|
||||
// FastGpt temperature range: 1~10
|
||||
temperature = +(modelConstantsData.maxTemperature * (temperature / 10)).toFixed(2);
|
||||
|
||||
const response = await chatCompletion({
|
||||
...req.body,
|
||||
res,
|
||||
model,
|
||||
temperature
|
||||
model
|
||||
});
|
||||
|
||||
if (stream) {
|
||||
@@ -88,6 +77,16 @@ export async function chatCompletion({
|
||||
limitPrompt = '',
|
||||
billId
|
||||
}: Props & { res: NextApiResponse }): Promise<Response> {
|
||||
// temperature adapt
|
||||
const modelConstantsData = getChatModel(model);
|
||||
|
||||
if (!modelConstantsData) {
|
||||
return Promise.reject('The chat model is undefined');
|
||||
}
|
||||
|
||||
// FastGpt temperature range: 1~10
|
||||
temperature = +(modelConstantsData.maxTemperature * (temperature / 10)).toFixed(2);
|
||||
|
||||
const messages: ChatItemType[] = [
|
||||
...(quotePrompt
|
||||
? [
|
||||
@@ -189,7 +188,7 @@ export async function chatCompletion({
|
||||
billId,
|
||||
moduleName: 'AI Chat',
|
||||
amount: countModelPrice({ model, tokens: totalTokens }),
|
||||
model,
|
||||
model: modelConstantsData.name,
|
||||
tokenLen: totalTokens
|
||||
});
|
||||
|
||||
|
@@ -7,6 +7,7 @@ import { ChatRoleEnum } from '@/constants/chat';
|
||||
import { modelToolMap } from '@/utils/plugin';
|
||||
import { getVector } from '../../plugin/vector';
|
||||
import { countModelPrice, pushTaskBillListItem } from '@/service/events/pushBill';
|
||||
import { getModel } from '@/service/utils/data';
|
||||
|
||||
export type QuoteItemType = {
|
||||
id: string;
|
||||
@@ -95,7 +96,7 @@ export async function kbSearch({
|
||||
billId,
|
||||
moduleName: 'Vector Generate',
|
||||
amount: countModelPrice({ model: vectorModel, tokens: tokenLen }),
|
||||
model: vectorModel,
|
||||
model: getModel(vectorModel)?.name,
|
||||
tokenLen
|
||||
})
|
||||
]);
|
||||
|
@@ -9,7 +9,7 @@ import { UserUpdateParams } from '@/types/user';
|
||||
/* 更新一些基本信息 */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
|
||||
try {
|
||||
const { openaiKey, avatar } = req.body as UserUpdateParams;
|
||||
const { avatar } = req.body as UserUpdateParams;
|
||||
|
||||
const { userId } = await authUser({ req, authToken: true });
|
||||
|
||||
@@ -20,8 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
_id: userId
|
||||
},
|
||||
{
|
||||
...(avatar && { avatar }),
|
||||
...(openaiKey !== undefined && { openaiKey })
|
||||
...(avatar && { avatar })
|
||||
}
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user