mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00

* add quote response filter (#4727) * chatting * add quote response filter * add test * remove comment * perf: cite hidden * perf: format llm response * feat: comment * update default chunk size * update default chunk size --------- Co-authored-by: heheer <heheer@sealos.io>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
|
|
import { PluginRuntimeType } from '@fastgpt/global/core/plugin/type';
|
|
import { splitCombinePluginId } from './controller';
|
|
import { PluginSourceEnum } from '@fastgpt/global/core/plugin/constants';
|
|
|
|
/*
|
|
Plugin points calculation:
|
|
1. 系统插件/商业版插件:
|
|
- 有错误:返回 0
|
|
- 无错误:返回 单次积分 + 子流程积分(可配置)
|
|
2. 个人插件
|
|
- 返回 子流程积分
|
|
*/
|
|
export const computedPluginUsage = async ({
|
|
plugin,
|
|
childrenUsage,
|
|
error
|
|
}: {
|
|
plugin: PluginRuntimeType;
|
|
childrenUsage: ChatNodeUsageType[];
|
|
error?: boolean;
|
|
}) => {
|
|
const { source } = await splitCombinePluginId(plugin.id);
|
|
const childrenUsages = childrenUsage.reduce((sum, item) => sum + (item.totalPoints || 0), 0);
|
|
|
|
if (source !== PluginSourceEnum.personal) {
|
|
if (error) return 0;
|
|
|
|
const pluginCurrentCost = plugin.currentCost ?? 0;
|
|
|
|
return plugin.hasTokenFee ? pluginCurrentCost + childrenUsages : pluginCurrentCost;
|
|
}
|
|
|
|
// Personal plugins are charged regardless of whether they are successful or not
|
|
return childrenUsages;
|
|
};
|