-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Expand file tree
/
Copy pathModelBadges.tsx
More file actions
90 lines (77 loc) · 1.82 KB
/
Copy pathModelBadges.tsx
File metadata and controls
90 lines (77 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import type { WorkersAIModelsSchema } from "~/schemas";
const ModelBadges = ({
model,
showTags = false,
}: {
model: WorkersAIModelsSchema;
showTags?: boolean;
}) => {
const badges = model.properties.flatMap(({ property_id, value }) => {
if (property_id === "lora" && value === "true") {
return {
variant: "tip",
text: "LoRA",
};
}
if (property_id === "function_calling" && value === "true") {
return {
variant: "note",
text: "Function calling",
};
}
if (property_id === "async_queue" && value === "true") {
return {
variant: "note",
text: "Batch",
};
}
if (property_id === "partner" && value === "true") {
return {
variant: "note",
text: "Partner",
};
}
if (property_id === "realtime" && value === "true") {
return {
variant: "note",
text: "Real-time",
};
}
if (property_id === "planned_deprecation_date") {
const timestamp = Math.floor(new Date(value as string).getTime());
if (Date.now() > timestamp) {
return { variant: "danger", text: "Deprecated" };
}
return { variant: "danger", text: "Planned deprecation" };
}
return [];
});
// Add tags as badges if showTags is enabled
const tagBadges =
showTags && model.tags
? model.tags.slice(0, 3).map((tag) => ({
variant: "default",
text: tag,
isTag: true,
}))
: [];
const allBadges = [...badges, ...tagBadges];
return (
<ul className="m-0 flex list-none flex-wrap items-center gap-2 p-0 text-xs">
{allBadges.map((badge) => (
<li key={badge.text} className="m-0">
<span
className={`sl-badge ${
"isTag" in badge && badge.isTag
? "bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-300"
: "default"
}`}
>
{badge.text}
</span>
</li>
))}
</ul>
);
};
export default ModelBadges;