Compare commits

..

No commits in common. "6f53b0dc9c993641b1e8b7ab26fe90508f1a6147" and "b107181752935b46b6b3d940cd2277363fad609c" have entirely different histories.

5 changed files with 15 additions and 67 deletions

View file

@ -1,17 +0,0 @@
{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": "https://thirdrule.gmem.ca/actor",
"type": "Person",
"preferredUsername": "thirdrule",
"inbox": "https://thirdrule.gmem.ca/inbox",
"discoverable": true,
"publicKey": {
"id": "https://thirdrule.gmem.ca/actor#main-key",
"owner": "https://thirdrule.gmem.ca/actor",
"publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyQMRCT3ZAmJXDiyVp3pf\nULqbCels2ZI/s0SDMwQtIbZPe1/d/IRkDJPeLtTXJJK1OpWk1BjKJX+UQNdKNFAY\nRoNybNvJ8H3i9qo54F2/aW5IH8MMfw1pJABAJACtU03uoqpRFFPNOrcB2AfIOJ9c\nckfMLMJljn/m7H1Niro1I0usfZbgtZUOPKTfZZresMDzfE1F4byzs6q+hkhGKA4J\n2zl224uIi3i1e98B8I73Ul6/+/x+OgAdA9OW6FXMqnF2+tSYkoXI/TVSCYBs9tdi\nkLA0Vj8dHW9zUkxIDImVZ+5gNWtIuU/3sZ3K/aXwr5E7fEZOvWWKLuLAQ+nARuiL\nKQIDAQAB\n-----END PUBLIC KEY-----\n"
}
}

View file

@ -1,11 +0,0 @@
{
"subject": "acct:thirdrule@thirdrule.gmem.ca",
"links": [
{
"rel": "self",
"type": "application/activity+json",
"href": "https://thirdrule.gmem.ca/actor"
}
]
}

View file

@ -1,35 +1,20 @@
import index from "./index.html";
import actor from "./ap/actor.json";
import webfinger from "./ap/webfinger.json";
async function generateRule(env) {
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.'
};
return await env.AI.run('@cf/meta/llama-3.1-8b-instruct', simple);
}
export default {
async scheduled(event, env, ctx) {
const rule = await generateRule(env);
console.log(`generated rule ${JSON.stringify(rule)}`);
ctx.waitUntil(env.LOG.put("LATEST", JSON.stringify(rule)));
ctx.waitUntil(env.LOG.put(Date.now(), JSON.stringify(rule), { expirationTtl: 31_536_000 }));
},
async fetch(request, env, ctx) {
const url = new URL(request.url);
const { pathname } = url;
const cacheUrl = new URL(request.url);
// Construct the cache key from the cache URL
const cacheKey = new Request(url.toString(), request);
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, {
@ -37,21 +22,19 @@ export default {
});
case "/rule.json":
const rule = await env.LOG.get("LATEST");
const response = new Response(rule, {
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=3600"}
"Cache-Control": "s-maxage=43200" }
});
ctx.waitUntil(cache.put(cacheKey, response.clone()));
return response;
case "/.well-known/webfinger":
return new Response(JSON.stringify(webfinger), {
headers: { "Content-Type": "application/json" }
});
case "/actor":
return new Response(JSON.stringify(actor), {
headers: { "Content-Type": "application/json" }
});
default:
return new Response("not found", {status: 404});
}

View file

@ -1,4 +1,4 @@
{
"name": "thirdrule",
"version": "1.0.0"
"version": "1.0.0",
}

View file

@ -5,10 +5,3 @@ account_id = "7dc420732ea679a530aee304ea49a63c"
[ai]
binding = "AI"
[triggers]
crons = ["0 0 * * *"]
[[kv_namespaces]]
binding = "LOG"
id = "b92ed82d29074a8eb892419703cfdfa5"