diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..41a2578 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.wrangler/ +node_modules/ diff --git a/index.html b/index.html new file mode 100644 index 0000000..9a617ee --- /dev/null +++ b/index.html @@ -0,0 +1,171 @@ + + + + + + + third rule + + + +
+
+

The Secret Third Rule

+
+
+

Generating

+
+ + +
+ + + + diff --git a/index.js b/index.js new file mode 100644 index 0000000..1f89c4a --- /dev/null +++ b/index.js @@ -0,0 +1,43 @@ +import index from "./index.html"; + +export default { + async fetch(request, env, ctx) { + const cacheUrl = new URL(request.url); + + // Construct the cache key from the cache URL + const cacheKey = new Request(cacheUrl.toString(), request); + const cache = caches.default; + let response = await cache.match(cacheKey); + if (response) { + return response; + } + + const url = new URL(request.url); + const { pathname } = url; + + switch (pathname) { + case "/": + return new Response(index, { + headers: { "Content-Type": "text/html" } + }); + + case "/rule.json": + const simple = { + prompt: 'Give me a rule for a Discord server that is surreal, bizzare, and outlandish while still being somewhat realistic on first glance. Keep it short and succinct. Do not add any additional information, greetings, or quotation marks.' + }; + + const reply = await env.AI.run('@cf/meta/llama-3.1-8b-instruct', simple); + + let response = new Response(JSON.stringify(reply), { + headers: { "Content-Type": "application/json", + "Cache-Control": "s-maxage=43200" } + }); + + ctx.waitUntil(cache.put(cacheKey, response.clone())); + return response; + default: + return new Response("not found", {status: 404}); + } + + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..6180b77 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "thirdrule", + "version": "1.0.0", + "license": "ISC" +} diff --git a/wrangler.toml b/wrangler.toml new file mode 100644 index 0000000..12f87a4 --- /dev/null +++ b/wrangler.toml @@ -0,0 +1,7 @@ +name = "thirdrule" +main = "index.js" +compatibility_date = "2023-08-23" +account_id = "7dc420732ea679a530aee304ea49a63c" + +[ai] +binding = "AI"