Ai
The Ai component lets you add a Cloudflare Workers AI binding to
your app.
Minimal example
const ai = new sst.cloudflare.Ai("MyAi");Link to a worker
You can link AI to a worker.
new sst.cloudflare.Worker("MyWorker", { handler: "./index.ts", link: [ai], url: true});Once linked, you can use the SDK to interact with the AI binding.
import { Resource } from "sst";
const result = await Resource.MyAi.run("@cf/meta/llama-3-8b-instruct", { prompt: "What is the origin of the phrase 'Hello, World'"});Constructor
new Ai(name, args?, opts?)Parameters
-
namestring -
args?AiArgs -
opts?ComponentResourceOptions
SDK
Use the SDK in your runtime to interact with your infrastructure.
Bindings
When you link an AI binding, it will be available to the worker and you can interact with it using its API methods.
import { Resource } from "sst";
const result = await Resource.MyAi.run("@cf/meta/llama-3-8b-instruct", { prompt: "What is the origin of the phrase 'Hello, World'"});