Skip to content

Commit 8d95d31

Browse files
committed
[Docs Site] Fetching Workers AI models at build-time
1 parent 09335b6 commit 8d95d31

File tree

76 files changed

+48
-21410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+48
-21410
lines changed

bin/fetch-ai-models.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/components/ModelCatalog.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { useEffect, useState } from "react";
22
import ModelInfo from "./models/ModelInfo";
33
import ModelBadges from "./models/ModelBadges";
44
import { authorData } from "./models/data";
5-
import type { WorkersAIModelsSchema } from "~/schemas";
65

76
type Filters = {
87
search: string;
@@ -11,7 +10,7 @@ type Filters = {
1110
capabilities: string[];
1211
};
1312

14-
const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
13+
const ModelCatalog = ({ models }: { models: any[] }) => {
1514
const [filters, setFilters] = useState<Filters>({
1615
search: "",
1716
authors: [],
@@ -39,18 +38,21 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
3938
model: {
4039
...model,
4140
capabilities: model.properties
42-
.flatMap(({ property_id, value }) => {
43-
if (property_id === "lora" && value === "true") {
41+
.flatMap((property: any) => {
42+
if (property.property_id === "lora" && property.value === "true") {
4443
return "LoRA";
4544
}
4645

47-
if (property_id === "function_calling" && value === "true") {
46+
if (
47+
property.property_id === "function_calling" &&
48+
property.value === "true"
49+
) {
4850
return "Function calling";
4951
}
5052

5153
return [];
5254
})
53-
.filter((p) => Boolean(p)),
55+
.filter((p: any) => Boolean(p)),
5456
},
5557
model_display_name: model.name.split("/").at(-1),
5658
}));
@@ -61,18 +63,21 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
6163
...new Set(
6264
models.flatMap((model) =>
6365
model.properties
64-
.flatMap(({ property_id, value }) => {
65-
if (property_id === "lora" && value === "true") {
66+
.flatMap((property: any) => {
67+
if (property.property_id === "lora" && property.value === "true") {
6668
return "LoRA";
6769
}
6870

69-
if (property_id === "function_calling" && value === "true") {
71+
if (
72+
property.property_id === "function_calling" &&
73+
property.value === "true"
74+
) {
7075
return "Function calling";
7176
}
7277

7378
return [];
7479
})
75-
.filter((p) => Boolean(p)),
80+
.filter((p: any) => Boolean(p)),
7681
),
7782
),
7883
];
@@ -91,7 +96,9 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
9196
}
9297

9398
if (filters.capabilities.length > 0) {
94-
if (!model.capabilities.some((c) => filters.capabilities.includes(c))) {
99+
if (
100+
!model.capabilities.some((c: any) => filters.capabilities.includes(c))
101+
) {
95102
return false;
96103
}
97104
}
@@ -231,8 +238,8 @@ const ModelCatalog = ({ models }: { models: WorkersAIModelsSchema[] }) => {
231238
)}
232239
{modelList.map((model) => {
233240
const isBeta = model.model.properties.find(
234-
({ property_id, value }) =>
235-
property_id === "beta" && value === "true",
241+
(property: any) =>
242+
property.property_id === "beta" && property.value === "true",
236243
);
237244

238245
const author = model.model.name.split("/")[1];

src/components/models/ModelBadges.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import type { WorkersAIModelsSchema } from "~/schemas";
2-
3-
const ModelBadges = ({ model }: { model: WorkersAIModelsSchema }) => {
4-
const badges = model.properties.flatMap(({ property_id, value }) => {
5-
if (property_id === "lora" && value === "true") {
1+
const ModelBadges = ({ model }: { model: any }) => {
2+
const badges = model.properties.flatMap((property: any) => {
3+
if (property.property_id === "lora" && property.value === "true") {
64
return {
75
variant: "tip",
86
text: "LoRA",
97
};
108
}
119

12-
if (property_id === "function_calling" && value === "true") {
10+
if (
11+
property.property_id === "function_calling" &&
12+
property.value === "true"
13+
) {
1314
return {
1415
variant: "note",
1516
text: "Function calling",
1617
};
1718
}
1819

19-
if (property_id === "planned_deprecation_date") {
20-
const timestamp = Math.floor(new Date(value).getTime() / 1000);
20+
if (property.property_id === "planned_deprecation_date") {
21+
const timestamp = Math.floor(new Date(property.value).getTime() / 1000);
2122

2223
if (Date.now() > timestamp) {
2324
return { variant: "danger", text: "Deprecated" };
@@ -31,7 +32,7 @@ const ModelBadges = ({ model }: { model: WorkersAIModelsSchema }) => {
3132

3233
return (
3334
<ul className="m-0 flex list-none items-center gap-2 p-0 text-xs">
34-
{badges.map((badge) => (
35+
{badges.map((badge: any) => (
3536
<li key={badge.text}>
3637
<span className="sl-badge default">{badge.text}</span>
3738
</li>

src/components/models/ModelFeatures.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import type { WorkersAIModelsSchema } from "~/schemas";
2-
3-
const ModelFeatures = ({ model }: { model: WorkersAIModelsSchema }) => {
1+
const ModelFeatures = ({ model }: { model: any }) => {
42
const nf = new Intl.NumberFormat("en-US");
53
const properties: any = {};
64
model.properties.forEach((property: any) => {

src/components/models/ModelInfo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { WorkersAIModelsSchema } from "~/schemas";
21
import { authorData } from "./data";
32

4-
const ModelInfo = ({ model }: { model: WorkersAIModelsSchema }) => {
3+
const ModelInfo = ({ model }: { model: any }) => {
54
const author =
65
authorData[model.name.split("/")[1]]?.name ?? model.name.split("/")[1];
76
return (

src/content.config.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
glossarySchema,
1717
learningPathsSchema,
1818
videosSchema,
19-
workersAiModelsSchema,
2019
warpReleasesSchema,
2120
releaseNotesSchema,
2221
fieldsSchema,
@@ -88,8 +87,20 @@ export const collections = {
8887
loader: dataLoader("products"),
8988
}),
9089
"workers-ai-models": defineCollection({
91-
loader: dataLoader("workers-ai-models"),
92-
schema: workersAiModelsSchema,
90+
loader: async () => {
91+
const res = await fetch("https://ai.cloudflare.com/api/models");
92+
93+
const data: { models: any[] } = await res.json();
94+
95+
return data.models.map((model) => {
96+
const id = model.name.split("/")[2];
97+
98+
return {
99+
id,
100+
...model,
101+
};
102+
});
103+
},
93104
}),
94105
videos: defineCollection({
95106
loader: file("src/content/videos/index.yaml"),

src/content/workers-ai-models/bart-large-cnn.json

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/content/workers-ai-models/bge-base-en-v1.5.json

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)