Skip to content

Commit

Permalink
Merge branch 'cloudflare:production' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
dherder authored Oct 22, 2024
2 parents 55665e3 + e61b087 commit a3aa00f
Show file tree
Hide file tree
Showing 155 changed files with 3,347 additions and 2,839 deletions.
12 changes: 6 additions & 6 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

# AI

/src/content/docs/ai-gateway/ @kathayl @G4brym @mchenco @pdwittig @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/docs/workers-ai/ @rita3ko @pdwittig @craigsdennis @markdembo @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/docs/ai-gateway/ @kathayl @G4brym @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/docs/workers-ai/ @rita3ko @craigsdennis @markdembo @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/docs/workers-ai/static @mchenco @craigsdennis @cloudflare/pcx-technical-writing
/src/content/docs/vectorize/ @elithrar @vy-ton @pdwittig @sejoker @cloudflare/pcx-technical-writing
/src/content/changelogs/workers-ai.yaml @kathayl @G4brym @mchenco @pdwittig @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/changelogs/ai-gateway.yaml @kathayl @G4brym @mchenco @pdwittig @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/changelogs/vectorize.yaml @elithrar @pdwittig @sejoker @cloudflare/pcx-technical-writing
/src/content/docs/vectorize/ @elithrar @vy-ton @sejoker @cloudflare/pcx-technical-writing
/src/content/changelogs/workers-ai.yaml @kathayl @G4brym @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/changelogs/ai-gateway.yaml @kathayl @G4brym @mchenco @daisyfaithauma @cloudflare/pcx-technical-writing
/src/content/changelogs/vectorize.yaml @elithrar @sejoker @cloudflare/pcx-technical-writing

# Analytics & Logs

Expand Down
1,243 changes: 366 additions & 877 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@
"@astro-community/astro-embed-youtube": "^0.5.5",
"@astrojs/check": "^0.9.4",
"@astrojs/react": "^3.6.2",
"@astrojs/rss": "^4.0.8",
"@astrojs/rss": "^4.0.9",
"@astrojs/sitemap": "^3.2.1",
"@astrojs/starlight": "^0.28.3",
"@astrojs/starlight-docsearch": "^0.2.0",
"@astrojs/starlight-tailwind": "^2.0.3",
"@astrojs/tailwind": "^5.1.2",
"@cloudflare/puppeteer": "^0.0.14",
"@cloudflare/vitest-pool-workers": "^0.5.19",
"@cloudflare/vitest-pool-workers": "^0.5.20",
"@cloudflare/workers-types": "^4.20240903.0",
"@codingheads/sticky-header": "^1.0.2",
"@stoplight/json-schema-tree": "^4.0.0",
"@types/dompurify": "^3.0.5",
"@types/he": "^1.2.3",
"@types/node": "^20.16.1",
"@types/node": "^22.7.7",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"algoliasearch": "^5.8.1",
"astro": "^4.16.4",
"algoliasearch": "^5.9.1",
"astro": "^4.16.6",
"astro-breadcrumbs": "^3.2.0",
"astro-icon": "^1.1.1",
"astro-live-code": "^0.0.3",
"date-fns": "^3.6.0",
"date-fns": "^4.1.0",
"detype": "1.0.12",
"dompurify": "3.1.6",
"dot-prop": "^9.0.0",
Expand All @@ -59,6 +59,7 @@
"mermaid": "^11.3.0",
"node-html-parser": "^6.1.13",
"patch-package": "^8.0.0",
"playwright": "^1.48.1",
"prettier": "^3.3.3",
"prettier-plugin-astro": "^0.14.1",
"puppeteer": "^23.6.0",
Expand All @@ -68,22 +69,22 @@
"redirects-in-workers": "^0.0.5",
"rehype-autolink-headings": "^7.1.0",
"rehype-external-links": "^3.0.0",
"rehype-mermaid": "^2.1.0",
"rehype-mermaid": "^3.0.0",
"rehype-title-figure": "^0.1.2",
"sharp": "^0.33.5",
"solarflare-theme": "^0.0.2",
"starlight-image-zoom": "^0.8.0",
"starlight-links-validator": "^0.12.0",
"starlight-package-managers": "^0.7.0",
"svgo": "^3.3.2",
"tailwindcss": "^3.4.10",
"tailwindcss": "^3.4.14",
"tippy.js": "^6.3.7",
"tsx": "^4.19.1",
"typescript": "^5.6.3",
"unist-util-visit": "^5.0.0",
"vitest": "2.1.3",
"wrangler": "^3.78.10",
"yaml": "^2.5.1"
"yaml": "^2.6.0"
},
"engines": {
"node": ">=22"
Expand Down
14 changes: 11 additions & 3 deletions public/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@
/ai/ /use-cases/ai/ 301

# AI Gateway

/ai-gateway/get-started/configuring-settings/ /ai-gateway/get-started/ 301
/ai-gateway/get-started/connecting-applications/ /ai-gateway/get-started/ 301
/ai-gateway/get-started/creating-gateway/ /ai-gateway/get-started/ 301
/ai-gateway/pricing/ /ai-gateway/reference/pricing/ 301
/ai-gateway/observability/evaluations/ /ai-gateway/evaluations/ 301
/ai-gateway/observability/evaluations/set-up-evaluations/ /ai-gateway/evaluations//set-up-evaluations/ 301

/ai-gateway/integration/vercel-ai-sdk/ /ai-gateway/integrations/vercel-ai-sdk/ 301
/ai-gateway/integration/aig-workers-ai-binding/ /ai-gateway/integrations/aig-workers-ai-binding/ 301
/ai-gateway/integration/ /ai-gateway/integrations/ 301

# analytics
/analytics/migration-guides/zone-analytics/ /analytics/graphql-api/migration-guides/zone-analytics/ 301
Expand Down Expand Up @@ -211,7 +212,8 @@
/cache/about/ /cache/concepts/ 301
/cache/concepts/enable-http2-to-origin/ /speed/optimization/protocol/http2-to-origin/ 301
/cache/how-to/enable-http2-to-origin/ /speed/optimization/protocol/http2-to-origin/ 301
/cache/how-to/interact-with-workers/ /cache/concepts/interact-with-workers/ 301
/cache/how-to/interact-with-workers/ /cache/interaction-cloudflare-products/workers/ 301
/cache/concepts/interact-with-workers/ /cache/interaction-cloudflare-products/workers/ 301
/cache/best-practices/cache-behavior/ /cache/concepts/cache-behavior/ 301
/cache/best-practices/customize-cache/ /cache/concepts/customize-cache/ 301
/cache/best-practices/ /cache/concepts/ 301
Expand Down Expand Up @@ -1124,6 +1126,9 @@
/support/account-management-billing/account-privacy-and-security/ /support/account-management-billing/ 301
/support/troubleshooting/general-troubleshooting/troubleshooting-surges-or-spikes-in-web-traffic/ /fundamentals/basic-tasks/preparing-for-surges-or-spikes-in-web-traffic/ 301
/support/troubleshooting/general-troubleshooting/preparing-for-surges-or-spikes-in-web-traffic/ /fundamentals/basic-tasks/preparing-for-surges-or-spikes-in-web-traffic/ 301
/support/third-party-software/others/configuring-an-amazon-web-services-static-site-to-use-cloudflare/ /rules/cloud-connector/providers/ 301
/support/third-party-software/others/enabling-cloudflare-ssl-on-azure-storage-static-web-hosting-applications/ /rules/cloud-connector/providers/ 301


# r2
/r2/platform/s3-compatibility/api/ /r2/api/s3/api/ 301
Expand Down Expand Up @@ -1498,6 +1503,7 @@
/workers-ai/platform/storage-options/ /workers/platform/storage-options/ 301
/workers-ai/configuration/workers-ai-sdk/ /workers-ai/configuration/bindings/ 301
/workers-ai/tutorials/creating-a-recommendation-api/ /developer-spotlight/tutorials/creating-a-recommendation-api/ 301
/workers/observability/baselime-integration/ /workers/observability/integrations/baselime-integration/ 301

# workers KV
/kv/platform/environments/ /kv/reference/environments/ 301
Expand Down Expand Up @@ -1655,6 +1661,7 @@
/cloudflare-one/identity/service-auth/service-tokens/ /cloudflare-one/identity/service-tokens/ 301
/cloudflare-one/identity/users/short-lived-certificates/ /cloudflare-one/connections/connect-networks/use-cases/ssh/ssh-infrastructure-access/ 301
/cloudflare-one/identity/users/validating-json/ /cloudflare-one/identity/authorization-cookie/validating-json/ 301
/cloudflare-one/policies/gateway/configuring-block-page/ /cloudflare-one/policies/gateway/block-page/ 301
/cloudflare-one/policies/lists/ /cloudflare-one/policies/gateway/lists 301
/cloudflare-one/policies/gateway/dns-policies/scheduled-dns-policies/ /cloudflare-one/policies/gateway/timed-policies/#scheduled-policies 301
/cloudflare-one/policies/zero-trust/ /cloudflare-one/policies/access/ 301
Expand Down Expand Up @@ -1714,6 +1721,7 @@
/cloudflare-one/tutorials/zsh-env-var/ /cloudflare-one/tutorials/cli/ 301

### DYNAMIC REDIRECTS ###
/*/sitemap.xml /sitemap-index.xml 301
/access/configuring-identity-providers/* /cloudflare-one/identity/idp-integration/:splat 301
/api-security/* /api-shield/:splat 301
/api-shield/products/* /api-shield/security/:splat 301
Expand Down
Binary file added src/assets/images/cache/workers-cache-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 17 additions & 7 deletions src/components/Stream.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
interface Props {
videoId: string;
videoTitle: string;
thumbnailStartTime: string;
thumbnailTimeOrURL: string;
}
const { videoId, videoTitle, thumbnailStartTime } = Astro.props;
const { videoId, videoTitle, thumbnailTimeOrURL } = Astro.props;
const customerId = "1mwganm1ma0xgnmj";
const baseUrl = `https://customer-${customerId}.cloudflarestream.com/`;
Expand All @@ -14,11 +14,20 @@ const url = new URL(`${videoId}/iframe`, baseUrl);
url.searchParams.set("preload", "true");
url.searchParams.set("letterboxColor", "transparent");
const thumbnailUrl = new URL(`${videoId}/thumbnails/thumbnail.jpg`, baseUrl);
thumbnailUrl.searchParams.set("fit", "crop");
thumbnailUrl.searchParams.set("time", thumbnailStartTime);
url.searchParams.set("poster", encodeURI(thumbnailUrl.toString()));
// full url option
if (thumbnailTimeOrURL !== undefined) {
if (!thumbnailTimeOrURL.startsWith("http")) {
const thumbnailUrl = new URL(`${videoId}/thumbnails/thumbnail.jpg`, baseUrl);
thumbnailUrl.searchParams.set("fit", "crop");
thumbnailUrl.searchParams.set("time", thumbnailTimeOrURL);
url.searchParams.set("poster", encodeURI(thumbnailUrl.toString()));
} else {
url.searchParams.set("poster", thumbnailTimeOrURL);
}
}
---

<div style="position: relative; padding-top: 56.25%">
Expand All @@ -28,8 +37,9 @@ url.searchParams.set("poster", encodeURI(thumbnailUrl.toString()));
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture;"
allowfullscreen="true"
title={videoTitle}
id={videoId}></iframe>
id={videoId}></iframe>
</div>
<a href="https://www.youtube.com/@CloudflareDevelopers" target="_blank">Watch more videos on our Developer Channel</a>
<script is:inline src="https://embed.cloudflarestream.com/embed/sdk.latest.js"
></script>
<script is:inline define:vars={{ vidId: videoId, videoTitle }}>
Expand Down
5 changes: 5 additions & 0 deletions src/content/changelogs/ai-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ productLink: "/ai-gateway/"
productArea: Developer platform
productAreaLink: /workers/platform/changelog/platform/
entries:
- publish_date: "2024-10-17"
title: Vercel SDK
description: |-
Added [Vercel AI SDK](https://sdk.vercel.ai/). The SDK supports many different AI providers, tools for streaming completions, and more.
- publish_date: "2024-09-26"
title: Persistent logs
description: |-
Expand Down
4 changes: 4 additions & 0 deletions src/content/changelogs/tunnel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ productLink: "/cloudflare-one/connections/connect-networks/"
productArea: Cloudflare One
productAreaLink: /cloudflare-one/changelog/
entries:
- publish_date: "2024-10-17"
title: Simplifed WARP Connector deployment
description: |-
You can now deploy WARP Connector using a simplified, guided workflow similar to `cloudflared` connectors. For detailed instructions, refer to the [WARP Connector documentation](/cloudflare-one/connections/connect-networks/private-net/warp-connector/).
- publish_date: "2024-10-10"
title: Bugfix for --grace-period
description: |-
Expand Down
3 changes: 3 additions & 0 deletions src/content/changelogs/waf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ entries:
individual_page: true
scheduled: true
link: "/waf/change-log/scheduled-changes/"
- publish_date: "2024-10-21"
individual_page: true
link: "/waf/change-log/2024-10-21/"
- publish_date: "2024-10-14"
individual_page: true
link: "/waf/change-log/2024-10-14/"
Expand Down
142 changes: 142 additions & 0 deletions src/content/docs/ai-gateway/integrations/aig-workers-ai-binding.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
---
title: Workers AI
pcx_content_type: tutorial
updated: 2024-10-17
---

import { Render, PackageManagers } from "~/components";

This guide will walk you through setting up and deploying a Workers AI project. You will use [Workers](/workers/), an AI Gateway binding, and a large language model (LLM), to deploy your first AI-powered application on the Cloudflare global network.

## Prerequisites

<Render file="prereqs" product="workers" />

## 1. Create a Worker Project

You will create a new Worker project using the create-Cloudflare CLI (C3). C3 is a command-line tool designed to help you set up and deploy new applications to Cloudflare.

Create a new project named `hello-ai` by running:

<PackageManagers type="create" pkg="cloudflare@latest" args={"hello-ai"} />

Running `npm create cloudflare@latest` will prompt you to install the create-cloudflare package and lead you through setup. C3 will also install [Wrangler](/workers/wrangler/), the Cloudflare Developer Platform CLI.

<Render
file="c3-post-run-steps"
product="workers"
params={{
category: "hello-world",
type: "Hello World Worker",
lang: "TypeScript",
}}
/>

This will create a new `hello-ai` directory. Your new `hello-ai` directory will include:

- A "Hello World" Worker at `src/index.ts`.
- A `wrangler.toml` configuration file.

Go to your application directory:

```bash
cd hello-ai
```

## 2. Connect your Worker to Workers AI

You must create an AI binding for your Worker to connect to Workers AI. Bindings allow your Workers to interact with resources, like Workers AI, on the Cloudflare Developer Platform.

To bind Workers AI to your Worker, add the following to the end of your `wrangler.toml` file:

```toml title="wrangler.toml"
[ai]
binding = "AI"
```

Your binding is [available in your Worker code](/workers/reference/migrate-to-module-workers/#bindings-in-es-modules-format) on [`env.AI`](/workers/runtime-apis/handlers/fetch/).

You will need to have your `gateway id` for the next step. You can learn [how to create an AI Gateway in this tutorial](/ai-gateway/get-started/).

## 3. Run an inference task containing AI Gateway in your Worker

You are now ready to run an inference task in your Worker. In this case, you will use an LLM, [`llama-3.1-8b-instruct-fast`](/workers-ai/models/llama-3.1-8b-instruct-fast/), to answer a question. Your gateway ID is found on the dashboard.

Update the `index.ts` file in your `hello-ai` application directory with the following code:

```typescript title="src/index.ts" {78-81}
export interface Env {
// If you set another name in wrangler.toml as the value for 'binding',
// replace "AI" with the variable name you defined.
AI: Ai;
}

export default {
async fetch(request, env): Promise<Response> {
// Specify the gateway label and other options here
const response = await env.AI.run("@cf/meta/llama-3.1-8b-instruct-fast", {
prompt: "What is the origin of the phrase Hello, World",
gateway: {
id: "GATEWAYID", // Use your gateway label here
skipCache: true, // Optional: Skip cache if needed
},
});

// Return the AI response as a JSON object
return new Response(JSON.stringify(response), {
headers: { "Content-Type": "application/json" },
});
},
} satisfies ExportedHandler<Env>;
```

Up to this point, you have created an AI binding for your Worker and configured your Worker to be able to execute the Llama 3.1 model. You can now test your project locally before you deploy globally.

## 4. Develop locally with Wrangler

While in your project directory, test Workers AI locally by running [`wrangler dev`](/workers/wrangler/commands/#dev):

```bash
npx wrangler dev
```

<Render file="ai-local-usage-charges" product="workers" />

You will be prompted to log in after you run `wrangler dev`. When you run `npx wrangler dev`, Wrangler will give you a URL (most likely `localhost:8787`) to review your Worker. After you go to the URL Wrangler provides, you will see a message that resembles the following example:

````json
{
"response": "A fascinating question!\n\nThe phrase \"Hello, World!\" originates from a simple computer program written in the early days of programming. It is often attributed to Brian Kernighan, a Canadian computer scientist and a pioneer in the field of computer programming.\n\nIn the early 1970s, Kernighan, along with his colleague Dennis Ritchie, were working on the C programming language. They wanted to create a simple program that would output a message to the screen to demonstrate the basic structure of a program. They chose the phrase \"Hello, World!\" because it was a simple and recognizable message that would illustrate how a program could print text to the screen.\n\nThe exact code was written in the 5th edition of Kernighan and Ritchie's book \"The C Programming Language,\" published in 1988. The code, literally known as \"Hello, World!\" is as follows:\n\n```
main()
{
printf(\"Hello, World!\");
}
```\n\nThis code is still often used as a starting point for learning programming languages, as it demonstrates how to output a simple message to the console.\n\nThe phrase \"Hello, World!\" has since become a catch-all phrase to indicate the start of a new program or a small test program, and is widely used in computer science and programming education.\n\nSincerely, I'm glad I could help clarify the origin of this iconic phrase for you!"
}
````

## 5. Deploy your AI Worker

Before deploying your AI Worker globally, log in with your Cloudflare account by running:

```bash
npx wrangler login
```

You will be directed to a web page asking you to log in to the Cloudflare dashboard. After you have logged in, you will be asked if Wrangler can make changes to your Cloudflare account. Scroll down and select **Allow** to continue.

Finally, deploy your Worker to make your project accessible on the Internet. To deploy your Worker, run:

```bash
npx wrangler deploy
```

Once deployed, your Worker will be available at a URL like:

```bash
https://hello-ai.<YOUR_SUBDOMAIN>.workers.dev
```

Your Worker will be deployed to your custom [`workers.dev`](/workers/configuration/routing/workers-dev/) subdomain. You can now visit the URL to run your AI Worker.

By completing this tutorial, you have created a Worker, connected it to Workers AI through an AI Gateway binding, and successfully ran an inference task using the Llama 3.1 model.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
pcx_content_type: configuration
title: Integration
title: Integrations
sidebar:
group:
hideIndex: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Below is a summary of each Analytics app tab.

These metrics include legitimate user requests as well as crawlers and threats. The Traffic tab features the following panels: 

* **Web Traffic** - Displays metrics for *Requests*, *Bandwidth*, *Unique Visitors*, and [*Status Codes*](/analytics/account-and-zone-analytics/status-codes/). If you are using Cloudflare Workers, subrequests data will not be visible in zone Traffic Analytics. Instead, you can find subrequests analytics under the **Workers & Pages** tab in the **Overview** section. Refer to [Worker Analytics](/analytics/account-and-zone-analytics/analytics-with-workers/#worker-analytics) for more information.
* **Web Traffic** - Displays metrics for *Requests*, *Bandwidth*, and *Unique Visitors*. If you are using Cloudflare Workers, subrequests data will not be visible in zone Traffic Analytics. Instead, you can find subrequests analytics under the **Workers & Pages** tab in the **Overview** section. Refer to [Worker Analytics](/analytics/account-and-zone-analytics/analytics-with-workers/#worker-analytics) for more information.
* **Web Traffic Requests by Country** - Is an interactive map that breaks down the number of requests by country.  This panel also includes a data table for **Top Traffic Countries / Regions** that display the countries with the most number of requests (up to five, if the data exists).
* **Share Your Stats -** Lets you share actual site statistics on social media (Twitter) for: *Bytes saved,* *SSL requests served*, and *attacks blocked*.

Expand Down
Loading

0 comments on commit a3aa00f

Please sign in to comment.