mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-08-02 23:11:14 +08:00
feat(ai): 实现AI模型调用的积分计费功能
- 后端根据请求体中的n参数计算AI调用次数并扣减用户积分 - 添加readAIRequestCount函数解析multipart/form-data和JSON格式的请求体获取调用次数 - 前端Canvas组件中显示预计消耗的积分数量 - 在助手面板、配置节点面板和提示面板中集成积分成本计算和展示 - 优化模型选择器在云端模式下的模型列表显示逻辑 - 添加CreditSymbol组件用于统一积分图标显示 - 实现requestCreditCost函数计算远程调用的积分消耗 - 更新文档中关于积分扣费和模型配置的相关说明
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import type { ComponentProps } from "react";
|
||||
import { Zap } from "lucide-react";
|
||||
|
||||
export function CreditSymbol({ className, ...props }: ComponentProps<"span">) {
|
||||
return (
|
||||
<span {...props} className={`inline-flex items-center justify-center ${className || ""}`}>
|
||||
<Zap className="size-[1em] fill-current" strokeWidth={2.4} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export type ModelCreditCost = {
|
||||
model: string;
|
||||
credits: number;
|
||||
};
|
||||
|
||||
export function modelCreditCost(modelCosts: ModelCreditCost[] | undefined, model: string) {
|
||||
return modelCosts?.find((item) => item.model === model)?.credits || 0;
|
||||
}
|
||||
|
||||
export function requestCreditCost(options: { channelMode: string; modelCosts?: ModelCreditCost[]; model: string; count?: string | number }) {
|
||||
if (options.channelMode !== "remote") return 0;
|
||||
const count = Math.max(1, Math.floor(Math.abs(Number(options.count)) || 1));
|
||||
return modelCreditCost(options.modelCosts, options.model) * count;
|
||||
}
|
||||
Reference in New Issue
Block a user