feat(pricing): add free-models pricing type filter and shining daily free banner in model square

This commit is contained in:
CaIon committed 2026-09-30 17:09:38 +08:00
1 parent cf06cd72be
commit 96b2966388
17 files changed
+233 -9

No files matched your search

@@ -0,0 +1,97 @@
/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import { Sparkles } from 'lucide-react'
import { useTranslation } from 'react-i18next'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { isFreeModel } from '../lib/model-helpers'
import type { PricingModel } from '../types'
export interface FreeModelsBannerProps {
models: PricingModel[]
onShowFree: () => void
className?: string
}
export function FreeModelsBanner(props: FreeModelsBannerProps) {
const { t } = useTranslation()
const freeModels = props.models.filter((model) => isFreeModel(model))
if (freeModels.length === 0) return null
const names = freeModels
.slice(0, 6)
.map((model) => model.model_name)
.join(', ')
const suffix = freeModels.length > 6 ? ` +${freeModels.length - 6}` : ''
return (
<div
role='group'
aria-label={t("Today's Free Models")}
className={cn(
'relative overflow-hidden rounded-xl border border-amber-500/30 bg-amber-500/5 p-3 sm:p-4',
props.className
)}
>
<div
aria-hidden
className='pointer-events-none absolute inset-0 bg-[radial-gradient(ellipse_60%_80%_at_20%_50%,oklch(0.8_0.16_95/12%)_0%,transparent_70%),radial-gradient(ellipse_50%_80%_at_80%_50%,oklch(0.9_0.16_100/10%)_0%,transparent_70%)]'
/>
<div className='relative flex flex-wrap items-center justify-between gap-3'>
<div className='flex min-w-0 items-center gap-2.5'>
<Sparkles aria-hidden className='free-banner-shine-dot size-5 shrink-0' />
<div className='min-w-0'>
<p className='flex items-center gap-1.5 text-sm font-bold sm:text-base'>
<span className='free-banner-shine-text'>
{t("Today's Free Models")}
</span>
<span
className='bg-muted text-muted-foreground rounded-md px-1.5 py-0.5 text-[11px] font-semibold'
aria-label={t('{{count}} free models available', {
count: freeModels.length,
})}
>
{freeModels.length}
</span>
</p>
<p
className='text-muted-foreground mt-0.5 truncate text-xs sm:text-[13px]'
title={names + suffix}
>
{names}
{suffix}
</p>
</div>
</div>
<Button
type='button'
size='sm'
variant='outline'
onClick={props.onShowFree}
className='border-amber-500/40 text-amber-600 hover:bg-amber-500/10 dark:text-amber-400'
aria-label={t('View all free models')}
>
{t('View all free models')}
</Button>
</div>
</div>
)
}
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
export { PricingSidebar } from './pricing-sidebar'
export { PricingToolbar } from './pricing-toolbar'
export { FreeModelsBanner } from './free-models-banner'
export { ModelCard } from './model-card'
export { ModelCardGrid } from './model-card-grid'
export { LoadingSkeleton } from './loading-skeleton'
@@ -40,6 +40,8 @@ export function ModelBillingModeBadge(props: ModelBillingModeBadgeProps) {
if (isDynamicPricingModel(props.model)) {
variant = 'warning'
} else if (labelKey === 'Free models') {
variant = 'success'
} else if (labelKey === 'Token-based') {
variant = 'info'
}
@@ -38,6 +38,7 @@ import {
getQuotaTypeLabels,
} from '../constants'
import { hasTaskUsageSchema } from '../lib/dynamic-price'
import { isFreeModel } from '../lib/model-helpers'
import { parseTags } from '../lib/filters'
import type { PricingModel, PricingVendor } from '../types'
@@ -218,6 +219,11 @@ export function PricingSidebar(props: PricingSidebarProps) {
label: quotaTypeLabels[QUOTA_TYPES.TASK],
count: countBy(props.models, (model) => hasTaskUsageSchema(model)),
},
{
value: QUOTA_TYPES.FREE,
label: quotaTypeLabels[QUOTA_TYPES.FREE],
count: countBy(props.models, (model) => isFreeModel(model)),
},
]
const tagOptions: FilterOption[] = [
+2
View File
@@ -50,6 +50,7 @@ export const QUOTA_TYPES = {
TOKEN: 'token',
REQUEST: 'request',
TASK: 'task',
FREE: 'free',
} as const
export type QuotaTypeOption = (typeof QUOTA_TYPES)[keyof typeof QUOTA_TYPES]
@@ -63,6 +64,7 @@ export function getQuotaTypeLabels(
[QUOTA_TYPES.TOKEN]: t('Token-based'),
[QUOTA_TYPES.REQUEST]: t('Per Request'),
[QUOTA_TYPES.TASK]: t('Task billing'),
[QUOTA_TYPES.FREE]: t('Free models'),
}
}
+8 -1
View File
@@ -31,8 +31,9 @@ import {
PricingToolbar,
ModelCardGrid,
ModelDetailsDrawer,
FreeModelsBanner,
} from './components'
import { EXCLUDED_GROUPS, VIEW_MODES } from './constants'
import { EXCLUDED_GROUPS, QUOTA_TYPES, VIEW_MODES } from './constants'
import { useFilters } from './hooks/use-filters'
import { usePricingData } from './hooks/use-pricing-data'
@@ -202,6 +203,12 @@ export function Pricing() {
/>
</header>
<FreeModelsBanner
models={models || []}
onShowFree={() => setQuotaTypeFilter(QUOTA_TYPES.FREE)}
className='mb-4'
/>
<div className='grid gap-4 xl:grid-cols-[280px_minmax(0,1fr)]'>
<PricingSidebar
quotaTypeFilter={quotaTypeFilter}
+3 -1
View File
@@ -18,13 +18,14 @@ For commercial licensing, please contact support@quantumnous.com
*/
import type { PricingModel } from '../types'
import { hasTaskUsageSchema, isDynamicPricingModel } from './dynamic-price'
import { isTokenBasedModel } from './model-helpers'
import { isFreeModel, isTokenBasedModel } from './model-helpers'
export type BillingModeLabelKey =
| 'Per Request'
| 'Dynamic Pricing'
| 'Token-based'
| 'Task billing'
| 'Free models'
export function getBillingModeLabelKey(
model: PricingModel
@@ -33,6 +34,7 @@ export function getBillingModeLabelKey(
// ($/1M token, $/credit, $/second) is already carried by the price line.
if (hasTaskUsageSchema(model)) return 'Task billing'
if (isDynamicPricingModel(model)) return 'Dynamic Pricing'
if (isFreeModel(model)) return 'Free models'
if (isTokenBasedModel(model)) return 'Token-based'
return 'Per Request'
}
+4
View File
@@ -25,6 +25,7 @@ import {
} from '../constants'
import type { PricingModel } from '../types'
import { hasTaskUsageSchema } from './dynamic-price'
import { isFreeModel } from './model-helpers'
// ----------------------------------------------------------------------------
// Filter Utilities
@@ -79,6 +80,9 @@ export function filterByQuotaType(
quotaType: string
): PricingModel[] {
if (quotaType === QUOTA_TYPES.ALL) return models
if (quotaType === QUOTA_TYPES.FREE) {
return models.filter((m) => isFreeModel(m))
}
// Task-usage models form their own bucket, disjoint from token/request.
if (quotaType === QUOTA_TYPES.TASK) {
return models.filter((m) => hasTaskUsageSchema(m))
@@ -107,3 +107,21 @@ export function replaceModelInPath(path: string, modelName: string): string {
export function isTokenBasedModel(model: PricingModel): boolean {
return model.quota_type === QUOTA_TYPE_VALUES.TOKEN
}
/**
* Check if a model is free of charge (0 price with standard billing).
* Covers both token-based models with zero ratios and per-request models
* with a zero fixed price. Dynamic/task-billing models are excluded because
* their cost cannot be derived from the static price fields.
*/
export function isFreeModel(model: PricingModel): boolean {
// Inline task/dynamic checks to avoid an import cycle with dynamic-price.ts.
const isTaskBilling = Object.keys(model.billing_usage_schema ?? {}).length > 0
const isDynamic =
model.billing_mode === 'tiered_expr' && Boolean(model.billing_expr)
if (isTaskBilling || isDynamic) return false
if (model.quota_type === QUOTA_TYPE_VALUES.TOKEN) {
return (model.model_ratio ?? 0) === 0
}
return (model.model_price ?? 0) === 0
}
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "Zero retention",
"Zhipu": "Zhipu",
"Zhipu V4": "Zhipu V4",
"Zoom": "Zoom"
"Zoom": "Zoom",
"Free models": "Free models",
"Today's Free Models": "Today's Free Models",
"{{count}} free models available": "{{count}} free models available",
"View all free models": "View all free models"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Recharge bonus: pay ¥{{pay}}, get ¥{{credit}} credited — the more you top up, the more you get.",
"Credited amount": "Credited amount",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "Aucune rétention",
"Zhipu": "Zhipu",
"Zhipu V4": "Zhipu V4",
"Zoom": "Zoom"
"Zoom": "Zoom",
"Free models": "Modèles gratuits",
"Today's Free Models": "Modèles gratuits du jour",
"{{count}} free models available": "{{count}} modèles gratuits disponibles",
"View all free models": "Voir tous les modèles gratuits"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Bonus de recharge : payez ¥{{pay}} et recevez ¥{{credit}} — plus vous rechargez, plus vous gagnez.",
"Credited amount": "Montant crédité",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "データ保持なし",
"Zhipu": "Zhipu",
"Zhipu V4": "Zhipu V 4",
"Zoom": "ズーム"
"Zoom": "ズーム",
"Free models": "無料モデル",
"Today's Free Models": "本日の無料モデル",
"{{count}} free models available": "無料モデル: {{count}}",
"View all free models": "すべての無料モデルを見る"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "チャージ特典:{{pay}}元の支払いで{{credit}}元が付与されます。金額が多いほどお得です。",
"Credited amount": "付与額",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "Без хранения данных",
"Zhipu": "Zhipu",
"Zhipu V4": "Zhipu V4",
"Zoom": "Zoom"
"Zoom": "Zoom",
"Free models": "Бесплатные модели",
"Today's Free Models": "Бесплатные модели сегодня",
"{{count}} free models available": "Доступно бесплатных моделей: {{count}}",
"View all free models": "Все бесплатные модели"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Бонус за пополнение: платите ¥{{pay}} — получаете ¥{{credit}}. Чем больше пополнение, тем больше бонус.",
"Credited amount": "Начислено",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "Không lưu dữ liệu",
"Zhipu": "Zhipu",
"Zhipu V4": "Zhipu V4",
"Zoom": "Zoom"
"Zoom": "Zoom",
"Free models": "Mô hình miễn phí",
"Today's Free Models": "Mô hình miễn phí hôm nay",
"{{count}} free models available": "{{count}} mô hình miễn phí",
"View all free models": "Xem tất cả mô hình miễn phí"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "Ưu đãi nạp tiền: nạp {{pay}} nhận {{credit}} — nạp càng nhiều nhận càng nhiều.",
"Credited amount": "Số tiền nhận được",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "零數據保留",
"Zhipu": "智譜",
"Zhipu V4": "智譜 V4",
"Zoom": "縮放"
"Zoom": "縮放",
"Free models": "免費模型",
"Today's Free Models": "今日免費模型",
"{{count}} free models available": "{{count}} 個免費模型",
"View all free models": "查看全部免費模型"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "儲值優惠:儲值 {{pay}} 元實際入帳 {{credit}} 元,以此類推,儲多少送多少。",
"Credited amount": "入帳金額",
+5 -1
View File
@@ -6144,7 +6144,11 @@
"Zero retention": "零数据保留",
"Zhipu": "智谱",
"Zhipu V4": "智谱 V4",
"Zoom": "缩放"
"Zoom": "缩放",
"Free models": "免费模型",
"Today's Free Models": "今日免费模型",
"{{count}} free models available": "{{count}} 个免费模型",
"View all free models": "查看全部免费模型"
},
"Recharge bonus: pay {{pay}} get {{credit}} — the more you top up, the more you get.": "充值优惠:充值 {{pay}} 元实际到账 {{credit}} 元,以此类推,充多少送多少。",
"Credited amount": "到账金额",
+57
View File
@@ -730,3 +730,60 @@ For commercial licensing, please contact support@quantumnous.com
display: none;
}
}
/* ── Model square free-models banner: shining text ── */
@keyframes free-banner-shine {
0% {
background-position: 200% center;
}
100% {
background-position: -200% center;
}
}
@keyframes free-banner-glow {
0%,
100% {
opacity: 0.55;
}
50% {
opacity: 1;
}
}
.free-banner-shine-text {
background: linear-gradient(
100deg,
oklch(0.75 0.13 85) 0%,
oklch(0.95 0.17 95) 20%,
oklch(0.85 0.16 75) 40%,
oklch(0.98 0.18 100) 60%,
oklch(0.75 0.13 85) 80%
);
background-size: 200% auto;
background-clip: text;
-webkit-background-clip: text;
color: transparent;
animation: free-banner-shine 3s linear infinite;
filter: drop-shadow(0 0 8px oklch(0.8 0.16 95 / 45%));
}
.free-banner-shine-dot {
color: oklch(0.95 0.18 100);
animation: free-banner-glow 1.6s ease-in-out infinite;
filter: drop-shadow(0 0 6px oklch(0.85 0.18 100 / 70%));
}
@media (prefers-reduced-motion: reduce) {
.free-banner-shine-text,
.free-banner-shine-dot {
animation: none;
}
.free-banner-shine-text {
background: none;
-webkit-background-clip: initial;
background-clip: initial;
color: oklch(0.85 0.16 95);
filter: none;
}
}