feat(ai): 实现AI模型调用的积分计费功能
- 后端根据请求体中的n参数计算AI调用次数并扣减用户积分 - 添加readAIRequestCount函数解析multipart/form-data和JSON格式的请求体获取调用次数 - 前端Canvas组件中显示预计消耗的积分数量 - 在助手面板、配置节点面板和提示面板中集成积分成本计算和展示 - 优化模型选择器在云端模式下的模型列表显示逻辑 - 添加CreditSymbol组件用于统一积分图标显示 - 实现requestCreditCost函数计算远程调用的积分消耗 - 更新文档中关于积分扣费和模型配置的相关说明
This commit is contained in:
@@ -9,6 +9,7 @@ import Link from "next/link";
|
||||
import { AnimatedThemeToggler } from "@/components/ui/animated-theme-toggler";
|
||||
import { GitHubLink } from "@/components/layout/github-link";
|
||||
import { VersionReleaseModal } from "@/components/layout/version-release-modal";
|
||||
import { CreditSymbol } from "@/constant/credits";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { canvasThemes } from "@/lib/canvas-theme";
|
||||
import { useConfigStore } from "@/stores/use-config-store";
|
||||
@@ -63,7 +64,7 @@ export function UserStatusActions({ showConfig = true, variant = "default", onOp
|
||||
{variant === "canvas" ? (
|
||||
<Tooltip title="当前算力点余额" placement="bottom">
|
||||
<div className="flex h-8 shrink-0 items-center gap-1.5 px-1.5 text-xs font-medium tabular-nums opacity-75 transition hover:opacity-100" style={{ color: canvasTheme.node.text }}>
|
||||
<span className="text-sm leading-none">⚡️</span>
|
||||
<CreditSymbol className="text-sm leading-none" />
|
||||
<span>{credits.toLocaleString()}</span>
|
||||
</div>
|
||||
</Tooltip>
|
||||
|
||||
@@ -20,7 +20,7 @@ type ModelPickerProps = {
|
||||
export function ModelPicker({ config, value, onChange, className, fullWidth = false, placeholder = "选择模型", onMissingConfig }: ModelPickerProps) {
|
||||
const pickerId = useId();
|
||||
const [open, setOpen] = useState(false);
|
||||
const options = useMemo(() => Array.from(new Set([value, ...config.models].filter(Boolean))), [config.models, value]);
|
||||
const options = useMemo(() => Array.from(new Set([...(config.channelMode === "local" ? [value] : []), ...config.models].filter(Boolean))), [config.channelMode, config.models, value]);
|
||||
const current = value || "";
|
||||
|
||||
useEffect(() => {
|
||||
@@ -36,7 +36,7 @@ export function ModelPicker({ config, value, onChange, className, fullWidth = fa
|
||||
open={open}
|
||||
value={current}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (nextOpen && !options.length) {
|
||||
if (nextOpen && !options.length && config.channelMode === "local") {
|
||||
onMissingConfig?.();
|
||||
return;
|
||||
}
|
||||
@@ -77,7 +77,7 @@ export function ModelPicker({ config, value, onChange, className, fullWidth = fa
|
||||
))
|
||||
) : (
|
||||
<SelectItem value="__empty__" disabled>
|
||||
请先到配置里拉取模型列表
|
||||
{config.channelMode === "remote" ? "暂无可用模型" : "请先到配置里拉取模型列表"}
|
||||
</SelectItem>
|
||||
)}
|
||||
</SelectContent>
|
||||
|
||||
Reference in New Issue
Block a user