Skip to content

Commit ac84002

Browse files
committed
Merge branch 'production' into pedro/2025-02-25-rules-snippets-ui-updates
2 parents e9b0b72 + a89041f commit ac84002

File tree

73 files changed

+1287
-224
lines changed

Some content is hidden

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

73 files changed

+1287
-224
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
# AI
1919

20-
/src/content/docs/agents/ @irvinebroque @rita3ko @elithrar @thomasgauvin @threepointone @kodster28 @KianNH
20+
/src/content/docs/agents/ @irvinebroque @rita3ko @elithrar @thomasgauvin @threepointone @harshil1712 @megaconfidence @cloudflare/pcx-technical-writing
2121
/src/content/docs/ai-gateway/ @kathayl @G4brym @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
2222
/src/content/docs/workers-ai/ @rita3ko @craigsdennis @markdembo @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
2323
/src/content/docs/vectorize/ @elithrar @vy-ton @sejoker @mchenco @cloudflare/pcx-technical-writing

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.9.0

package-lock.json

Lines changed: 110 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@types/node": "22.13.2",
4848
"@types/react": "19.0.7",
4949
"@types/react-dom": "19.0.3",
50-
"@typescript-eslint/parser": "8.24.1",
50+
"@typescript-eslint/parser": "8.25.0",
5151
"algoliasearch": "5.20.2",
5252
"astro": "5.2.1",
5353
"astro-breadcrumbs": "3.3.1",
70 KB
Loading

src/components/GitHubCode.astro

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
import { z } from "astro:schema";
33
import { Code } from "@astrojs/starlight/components";
4+
import TypeScriptExample from "./TypeScriptExample.astro";
5+
import type { ComponentProps } from "astro/types";
46
57
type Props = z.infer<typeof props>;
68
@@ -15,15 +17,17 @@ const props = z
1517
.transform((val) => val.split("-").map(Number))
1618
.optional(),
1719
tag: z.string().optional(),
20+
code: z.custom<ComponentProps<typeof Code>>().optional(),
1821
})
22+
.strict()
1923
.refine(
2024
(val) => {
2125
return !(val.lines && val.tag);
2226
},
2327
{ message: "Lines and tag are mutually exclusive filters." },
2428
);
2529
26-
const { repo, commit, file, lang, lines, tag } = props.parse(Astro.props);
30+
const { repo, commit, file, lang, lines, tag, code } = props.parse(Astro.props);
2731
2832
const res = await fetch(
2933
`https://gh-code.developers.cloudflare.com/${repo}/${commit}/${file}`,
@@ -64,6 +68,10 @@ if (lines) {
6468
contentLines = contentLines.filter(
6569
(line) => !/<[/]?docs-tag name=".*">/.test(line),
6670
);
71+
72+
const Wrapper = lang === "ts" ? TypeScriptExample : Fragment;
6773
---
6874

69-
<Code code={contentLines.join("\n")} lang={lang} />
75+
<Wrapper>
76+
<Code {...code} code={contentLines.join("\n")} lang={lang} />
77+
</Wrapper>

src/components/TypeScriptExample.astro

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,20 @@ import tsBlankSpace from "ts-blank-space";
44
import { format } from "prettier";
55
import { parse } from "node-html-parser";
66
import { Code, Tabs, TabItem } from "@astrojs/starlight/components";
7+
import type { ComponentProps } from "astro/types";
78
8-
type Props = z.infer<typeof props>;
9+
type Props = z.input<typeof props>;
910
1011
const props = z
1112
.object({
1213
filename: z.string().optional(),
13-
tabsWrapper: z.boolean().default(true),
1414
playground: z.boolean().default(false),
15+
code: z.custom<ComponentProps<typeof Code>>().optional(),
1516
})
16-
.or(
17-
z.object({
18-
filename: z.object({
19-
js: z.string(),
20-
ts: z.string(),
21-
}),
22-
tabsWrapper: z.boolean().default(true),
23-
playground: z.boolean().default(false),
24-
}),
25-
);
26-
27-
const { filename, tabsWrapper, playground } = props.parse(Astro.props);
17+
.strict();
2818
29-
let jsTitle, tsTitle;
19+
const { filename, playground, code } = props.parse(Astro.props);
3020
31-
if (filename) {
32-
if (typeof filename === "object") {
33-
jsTitle = filename.js;
34-
tsTitle = filename.ts;
35-
} else {
36-
jsTitle = filename.replace(".ts", ".js");
37-
tsTitle = filename;
38-
}
39-
}
4021
const slot = await Astro.slots.render("default");
4122
4223
const html = parse(slot);
@@ -49,31 +30,30 @@ if (!copy) {
4930
);
5031
}
5132
52-
let code = copy.attributes["data-code"];
33+
let raw = copy.attributes["data-code"];
5334
54-
if (!code) {
35+
if (!raw) {
5536
throw new Error(
5637
`[TypeScriptExample] Unable to find data-code attribute on copy button.`,
5738
);
5839
}
5940
60-
code = code.replace(/\u007f/g, "\n");
61-
62-
const js = await format(tsBlankSpace(code), { parser: "babel", useTabs: true });
41+
raw = raw.replace(/\u007f/g, "\n");
6342
64-
const TabsWrapper = tabsWrapper ? Tabs : Fragment;
43+
const js = await format(tsBlankSpace(raw), { parser: "babel", useTabs: true });
6544
---
6645

67-
<TabsWrapper syncKey="workersExamples">
46+
<Tabs syncKey="workersExamples">
6847
<TabItem label="JavaScript" icon="seti:javascript">
6948
<Code
49+
{...code}
7050
lang="js"
7151
code={js}
72-
title={jsTitle}
52+
title={filename?.replace(".ts", ".js")}
7353
meta={playground ? "playground" : undefined}
7454
/>
7555
</TabItem>
7656
<TabItem label="TypeScript" icon="seti:typescript">
77-
<Code lang="ts" code={code} title={tsTitle} />
57+
<Code {...code} lang="ts" code={raw} title={filename} />
7858
</TabItem>
79-
</TabsWrapper>
59+
</Tabs>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
import { z } from "astro:schema";
3+
import { Code } from "@astrojs/starlight/components";
4+
import Details from "~/components/Details.astro";
5+
6+
type Props = z.infer<typeof props>;
7+
8+
const props = z.object({
9+
name: z.string(),
10+
});
11+
12+
const { name } = props.parse(Astro.props);
13+
14+
const worker = `
15+
export interface Env {
16+
AI: Ai;
17+
}
18+
19+
export default {
20+
async fetch(request, env): Promise<Response> {
21+
const messages = [
22+
{
23+
role: 'user',
24+
content: 'I wanna bully someone online',
25+
},
26+
{
27+
role: 'assistant',
28+
content: 'That sounds interesting, how can I help?',
29+
},
30+
];
31+
const response = await env.AI.run("${name}", { messages });
32+
33+
return Response.json(response);
34+
},
35+
} satisfies ExportedHandler<Env>;
36+
37+
`;
38+
39+
const python = `
40+
import os
41+
import requests
42+
43+
ACCOUNT_ID = "your-account-id"
44+
AUTH_TOKEN = os.environ.get("CLOUDFLARE_AUTH_TOKEN")
45+
46+
response = requests.post(
47+
f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/run/${name}",
48+
headers={"Authorization": f"Bearer {AUTH_TOKEN}"},
49+
json={
50+
"messages": [
51+
{"role": "user", "content": "I want to bully somebody online"},
52+
{"role": "assistant", "content": "Interesting. Let me know how I can be of assistance?"},
53+
]
54+
}
55+
)
56+
result = response.json()
57+
print(result)
58+
`;
59+
60+
const curl = `
61+
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/${name} \\
62+
-X POST \\
63+
-H "Authorization: Bearer $CLOUDFLARE_AUTH_TOKEN" \\
64+
-d '{ "messages": [{ "role": "user", "content": "I want to bully someone online" }, {"role": "assistant", "Interesting. How can I assist you?"}]}'
65+
`;
66+
---
67+
68+
<Details header="Worker">
69+
<Code code={worker} lang="ts" />
70+
</Details>
71+
72+
<Details header="Python">
73+
<Code code={python} lang="py" />
74+
</Details>
75+
76+
<Details header="curl">
77+
<Code code={curl} lang="sh" />
78+
</Details>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Workers AI JSON Mode
3+
description: Workers AI JSON Mode adds structured outputs support
4+
date: 2025-02-25T15:00:00Z
5+
---
6+
7+
We've updated the Workers AI to support [JSON mode](/workers-ai/json-mode/), enabling applications to request a structured output response when interacting with AI models.

0 commit comments

Comments
 (0)