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
}