1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useState , useMemo } from "react" ;
22import ModelInfo from "./models/ModelInfo" ;
33import ModelBadges from "./models/ModelBadges" ;
44import { authorData } from "./models/data" ;
@@ -19,6 +19,37 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
1919 capabilities : [ ] ,
2020 } ) ;
2121
22+ // List of model names to pin at the top
23+ const pinnedModelNames = [
24+ "@cf/meta/llama-3.3-70b-instruct-fp8-fast" ,
25+ "@cf/meta/llama-3.1-8b-instruct-fast" ,
26+ ] ;
27+
28+ // Sort models by pinned status first, then by created_at date
29+ const sortedModels = useMemo ( ( ) => {
30+ return [ ...models ] . sort ( ( a , b ) => {
31+ // First check if either model is pinned
32+ const isPinnedA = pinnedModelNames . includes ( a . name ) ;
33+ const isPinnedB = pinnedModelNames . includes ( b . name ) ;
34+
35+ // If pinned status differs, prioritize pinned models
36+ if ( isPinnedA && ! isPinnedB ) return - 1 ;
37+ if ( ! isPinnedA && isPinnedB ) return 1 ;
38+
39+ // If both are pinned, sort by position in pinnedModelNames array (for manual ordering)
40+ if ( isPinnedA && isPinnedB ) {
41+ return (
42+ pinnedModelNames . indexOf ( a . name ) - pinnedModelNames . indexOf ( b . name )
43+ ) ;
44+ }
45+
46+ // If neither is pinned, sort by created_at date (newest first)
47+ const dateA = a . created_at ? new Date ( a . created_at ) : new Date ( 0 ) ;
48+ const dateB = b . created_at ? new Date ( b . created_at ) : new Date ( 0 ) ;
49+ return dateB . getTime ( ) - dateA . getTime ( ) ;
50+ } ) ;
51+ } , [ models ] ) ;
52+
2253 useEffect ( ( ) => {
2354 const params = new URLSearchParams ( window . location . search ) ;
2455
@@ -35,7 +66,7 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
3566 } ) ;
3667 } , [ ] ) ;
3768
38- const mapped = models . map ( ( model ) => ( {
69+ const mapped = sortedModels . map ( ( model ) => ( {
3970 model : {
4071 ...model ,
4172 capabilities : model . properties
@@ -237,13 +268,19 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
237268
238269 const author = model . model . name . split ( "/" ) [ 1 ] ;
239270 const authorInfo = authorData [ author ] ;
271+ const isPinned = pinnedModelNames . includes ( model . model . name ) ;
240272
241273 return (
242274 < a
243275 key = { model . model . id }
244- className = "mb-3 block w-full self-start rounded-md border border-solid border-gray-200 p-3 !text-inherit no-underline hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-gray-800 lg:w-[48%]"
276+ className = "relative mb-3 block w-full self-start rounded-md border border-solid border-gray-200 p-3 !text-inherit no-underline hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-gray-800 lg:w-[48%]"
245277 href = { `/workers-ai/models/${ model . model_display_name } ` }
246278 >
279+ { isPinned && (
280+ < span className = "absolute right-2 top-1" title = "Pinned model" >
281+ 📌
282+ </ span >
283+ ) }
247284 < div className = "-mb-1 flex items-center" >
248285 { authorInfo ?. logo ? (
249286 < img
0 commit comments