feat(*): 模型生成链路 - 完善 Agnes 结果兼容、价格展示与请求日志追踪
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import type { ComponentProps } from "react";
|
||||
import { Coins } from "lucide-react";
|
||||
|
||||
export { requestCreditCost } from "@/lib/model-pricing";
|
||||
|
||||
export function CreditSymbol({ className, ...props }: ComponentProps<"span">) {
|
||||
return (
|
||||
<span {...props} className={`inline-flex items-center justify-center ${className || ""}`}>
|
||||
@@ -9,31 +11,6 @@ export function CreditSymbol({ className, ...props }: ComponentProps<"span">) {
|
||||
);
|
||||
}
|
||||
|
||||
export type ModelCreditCost = {
|
||||
model: string;
|
||||
pricePolicy?: "channel" | "unified";
|
||||
billingMode: "fixed_request" | "per_second" | "token";
|
||||
unitPriceMicrocredits: number;
|
||||
};
|
||||
|
||||
function modelCreditCost(modelCosts: ModelCreditCost[] | undefined, model: string) {
|
||||
return modelCosts?.find((item) => item.model === model) || null;
|
||||
}
|
||||
|
||||
export function formatCredits(value: number, maximumFractionDigits = 6) {
|
||||
return (value / 1_000_000).toLocaleString("zh-CN", { maximumFractionDigits });
|
||||
}
|
||||
|
||||
export function requestCreditCost(options: { channelMode: string; modelCosts?: ModelCreditCost[]; model: string; count?: string | number; seconds?: string | number }) {
|
||||
if (options.channelMode !== "remote") return null;
|
||||
const cost = modelCreditCost(options.modelCosts, options.model);
|
||||
if (!cost) return null;
|
||||
// 跟随供应价格的前台模型只有后端完成能力路由后才能确定价格,前端不展示误导性预估。
|
||||
if (cost.pricePolicy === "channel") return null;
|
||||
// Token 订单由服务端按请求体预授权并在 usage 返回后结算,前端不展示无依据的固定价格。
|
||||
if (cost.billingMode === "token") return null;
|
||||
const quantity = cost.billingMode === "per_second"
|
||||
? Math.max(1, Math.floor(Math.abs(Number(options.seconds)) || 1))
|
||||
: Math.max(1, Math.floor(Math.abs(Number(options.count)) || 1));
|
||||
return (cost.unitPriceMicrocredits / 1_000_000) * quantity;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user