perf: bill

This commit is contained in:
archer
2023-07-13 22:53:44 +08:00
parent 726de0396b
commit f3715731c4
67 changed files with 915 additions and 1254 deletions

View File

@@ -5,7 +5,6 @@ import { ChatItemType } from '@/types/chat';
import { ChatCompletionRequestMessageRoleEnum } from 'openai';
import { ChatRoleEnum } from '@/constants/chat';
import type { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
import { ChatModelMap, OpenAiChatEnum } from '@/constants/model';
import type { AppModuleItemType } from '@/types/app';
import type { FlowModuleItemType } from '@/types/flow';
import type { Edge, Node } from 'reactflow';
@@ -16,12 +15,10 @@ const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz1234567890', 6);
export const adaptBill = (bill: BillSchema): UserBillType => {
return {
id: bill._id,
type: bill.type,
modelName: ChatModelMap[bill.modelName as `${OpenAiChatEnum}`]?.name || bill.modelName,
source: bill.source,
time: bill.time,
textLen: bill.textLen,
tokenLen: bill.tokenLen,
price: formatPrice(bill.price)
total: formatPrice(bill.total),
appName: bill.appName
};
};

View File

@@ -50,10 +50,10 @@ export const adaptChatItem_openAI = ({
export function countOpenAIToken({
messages,
model
model = 'gpt-3.5-turbo'
}: {
messages: ChatItemType[];
model: `${OpenAiChatEnum}`;
model?: string;
}) {
const diffVal = model.startsWith('gpt-3.5-turbo') ? 3 : 2;
@@ -74,7 +74,7 @@ export const openAiSliceTextByToken = ({
text,
length
}: {
model: `${OpenAiChatEnum}`;
model: string;
text: string;
length: number;
}) => {