V4.8.17 feature (#3493)

* split tokens into input and output (#3477)

* split tokens into input and output

* query extension & tool call & question guide

* fix

* perf: input and output tokens

* perf: tool call if else

* perf: remove code

* fix: extract usage count

* fix: qa usage count

---------

Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
Archer
2024-12-30 10:13:25 +08:00
committed by GitHub
parent da2831b948
commit 50bf7f9a3b
46 changed files with 467 additions and 230 deletions

View File

@@ -37,7 +37,7 @@ async function handler(
const qgModel = global.llmModels[0];
const { result, tokens } = await createQuestionGuide({
const { result, inputTokens, outputTokens } = await createQuestionGuide({
messages,
model: qgModel.model
});
@@ -47,7 +47,8 @@ async function handler(
});
pushQuestionGuideUsage({
tokens,
inputTokens,
outputTokens,
teamId,
tmbId
});

View File

@@ -52,14 +52,15 @@ async function handler(req: ApiRequestProps<CreateQuestionGuideParams>, res: Nex
const qgModel = questionGuide?.model || global.llmModels[0].model;
const { result, tokens } = await createQuestionGuide({
const { result, inputTokens, outputTokens } = await createQuestionGuide({
messages,
model: qgModel,
customPrompt: questionGuide?.customPrompt
});
pushQuestionGuideUsage({
tokens,
inputTokens,
outputTokens,
teamId,
tmbId
});

View File

@@ -89,7 +89,7 @@ async function handler(req: NextApiRequest) {
pushGenerateVectorUsage({
teamId,
tmbId,
tokens,
inputTokens: tokens,
model: vectorModelData.model
});

View File

@@ -36,7 +36,7 @@ async function handler(req: ApiRequestProps<UpdateDatasetDataProps>) {
pushGenerateVectorUsage({
teamId,
tmbId,
tokens,
inputTokens: tokens,
model: vectorModel
});
} else {

View File

@@ -74,14 +74,15 @@ async function handler(req: NextApiRequest) {
const { totalPoints } = pushGenerateVectorUsage({
teamId,
tmbId,
tokens,
inputTokens: tokens,
model: dataset.vectorModel,
source: apikey ? UsageSourceEnum.api : UsageSourceEnum.fastgpt,
...(aiExtensionResult &&
extensionModel && {
extensionModel: extensionModel.name,
extensionTokens: aiExtensionResult.tokens
extensionInputTokens: aiExtensionResult.inputTokens,
extensionOutputTokens: aiExtensionResult.outputTokens
})
});
if (apikey) {

View File

@@ -57,7 +57,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse<any>) {
const { totalPoints } = pushGenerateVectorUsage({
teamId,
tmbId,
tokens,
inputTokens: tokens,
model,
billId,
source: getUsageSourceByAuthType({ authType })