|
@@ -1,10 +1,13 @@
|
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
|
|
|
+import { useQuery } from '@tanstack/react-query'
|
|
|
import { ChevronLeft, ChevronRight } from 'lucide-react'
|
|
import { ChevronLeft, ChevronRight } from 'lucide-react'
|
|
|
import { useTranslation } from 'react-i18next'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
import { Button } from '@/components/ui/button'
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
+import { getPerfMetricsSummary } from '../api'
|
|
|
import { DEFAULT_PRICING_PAGE_SIZE, DEFAULT_TOKEN_UNIT } from '../constants'
|
|
import { DEFAULT_PRICING_PAGE_SIZE, DEFAULT_TOKEN_UNIT } from '../constants'
|
|
|
import type { PricingModel, TokenUnit } from '../types'
|
|
import type { PricingModel, TokenUnit } from '../types'
|
|
|
import { ModelCard } from './model-card'
|
|
import { ModelCard } from './model-card'
|
|
|
|
|
+import type { ModelPerfBadgeData } from './model-perf-badge'
|
|
|
|
|
|
|
|
export interface ModelCardGridProps {
|
|
export interface ModelCardGridProps {
|
|
|
models: PricingModel[]
|
|
models: PricingModel[]
|
|
@@ -22,6 +25,13 @@ export function ModelCardGrid(props: ModelCardGridProps) {
|
|
|
const tokenUnit = props.tokenUnit ?? DEFAULT_TOKEN_UNIT
|
|
const tokenUnit = props.tokenUnit ?? DEFAULT_TOKEN_UNIT
|
|
|
const totalPages = Math.max(1, Math.ceil(props.models.length / pageSize))
|
|
const totalPages = Math.max(1, Math.ceil(props.models.length / pageSize))
|
|
|
|
|
|
|
|
|
|
+ const perfQuery = useQuery({
|
|
|
|
|
+ queryKey: ['perf-metrics-summary'],
|
|
|
|
|
+ queryFn: () => getPerfMetricsSummary(24),
|
|
|
|
|
+ staleTime: 60 * 1000,
|
|
|
|
|
+ retry: false,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
setPage(1)
|
|
setPage(1)
|
|
|
}, [props.models])
|
|
}, [props.models])
|
|
@@ -31,6 +41,16 @@ export function ModelCardGrid(props: ModelCardGridProps) {
|
|
|
return props.models.slice(start, start + pageSize)
|
|
return props.models.slice(start, start + pageSize)
|
|
|
}, [page, pageSize, props.models])
|
|
}, [page, pageSize, props.models])
|
|
|
|
|
|
|
|
|
|
+ const perfMap = useMemo(() => {
|
|
|
|
|
+ const map = new Map<string, ModelPerfBadgeData>()
|
|
|
|
|
+ for (const model of perfQuery.data?.data?.models ?? []) {
|
|
|
|
|
+ if (model.request_count > 0) {
|
|
|
|
|
+ map.set(model.model_name, model)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return map
|
|
|
|
|
+ }, [perfQuery.data])
|
|
|
|
|
+
|
|
|
if (props.models.length === 0) {
|
|
if (props.models.length === 0) {
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
@@ -46,6 +66,7 @@ export function ModelCardGrid(props: ModelCardGridProps) {
|
|
|
priceRate={props.priceRate}
|
|
priceRate={props.priceRate}
|
|
|
usdExchangeRate={props.usdExchangeRate}
|
|
usdExchangeRate={props.usdExchangeRate}
|
|
|
showRechargePrice={props.showRechargePrice}
|
|
showRechargePrice={props.showRechargePrice}
|
|
|
|
|
+ perf={perfMap.get(model.model_name || '')}
|
|
|
onClick={() => props.onModelClick(model.model_name || '')}
|
|
onClick={() => props.onModelClick(model.model_name || '')}
|
|
|
/>
|
|
/>
|
|
|
))}
|
|
))}
|