t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Cloudflare/AI/fixtures/AiAsyncHandler.ts
Julius Marminge 108e01746c
Upgrade Effect and Alchemy betas (#4643)
Prepare Relay production infrastructure for the PlanetScale PS_20 HA topology, upgrade Effect and Alchemy to compatible betas, reconcile migration state, and preserve patched MCP session termination behavior.\n\nCo-authored-by: codex <codex@users.noreply.github.com>
2026-07-27 16:21:02 +02:00

31 lines
884 B
TypeScript

import type { AiAsyncWorkerEnv } from "./AiAsyncWorker.ts";
const MODEL = "@cf/meta/llama-3.3-70b-instruct-fp8-fast";
export default {
async fetch(request: Request, env: AiAsyncWorkerEnv): Promise<Response> {
const url = new URL(request.url);
const prompt =
url.searchParams.get("prompt") ??
"Say the single word 'pong' and nothing else.";
if (url.pathname === "/run") {
const result = await env.AI.run(MODEL, {
messages: [{ role: "user", content: prompt }],
max_tokens: 128,
});
return Response.json({ mode: "async", result });
}
if (url.pathname === "/models") {
const models = await env.AI.models({ search: "llama-3.3" });
return Response.json({
mode: "async",
count: models.length,
names: models.map((m) => m.name),
});
}
return new Response("ok");
},
};