The best way to control Claude Code, Codex and more from any computer or phone

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