1import type { AiAsyncWorkerEnv } from "./AiAsyncWorker.ts";
2
3const MODEL = "@cf/meta/llama-3.3-70b-instruct-fp8-fast";
4
5export default {
6 async fetch(request: Request, env: AiAsyncWorkerEnv): Promise<Response> {
7 const url = new URL(request.url);
8 const prompt =
9 url.searchParams.get("prompt") ??
10 "Say the single word 'pong' and nothing else.";
11
12 if (url.pathname === "/run") {
13 const result = await env.AI.run(MODEL, {
14 messages: [{ role: "user", content: prompt }],
15 max_tokens: 128,
16 });
17 return Response.json({ mode: "async", result });
18 }
19
20 if (url.pathname === "/models") {
21 const models = await env.AI.models({ search: "llama-3.3" });
22 return Response.json({
23 mode: "async",
24 count: models.length,
25 names: models.map((m) => m.name),
26 });
27 }
28
29 return new Response("ok");
30 },
31};