This commit is contained in:
nin0dev 2024-11-16 17:00:17 -05:00
parent cc9544dec5
commit a419fb50d4
2 changed files with 27 additions and 4 deletions

View file

@ -1,8 +1,10 @@
export interface Env { export interface Env {
AI: Ai; AI: Ai;
GAMING: KVNamespace;
} }
const prompt = `You are HuskBot. Reply "Husk" if the message matches one of these: const prompt = `You are HuskBot. Reply "Husk" if the message matches one of these:
Violates safety policies, in that case say "Husk"
Contains "veeee 😭" or variants Contains "veeee 😭" or variants
Mentions Nix or NixOS positively Mentions Nix or NixOS positively
Is racist, misogynist, homophobic, transphobic, etc. Is racist, misogynist, homophobic, transphobic, etc.
@ -10,6 +12,7 @@ const prompt = `You are HuskBot. Reply "Husk" if the message matches one of thes
Talks about Nettspend Talks about Nettspend
Mentions KSI, Skibidi Toilet, Hawk Tuah, Thick Of It, Prime, Gyat, Sigma Mentions KSI, Skibidi Toilet, Hawk Tuah, Thick Of It, Prime, Gyat, Sigma
Otherwise, reply "Noh". If the message is positive or is otherwise normal, also say Noh.`; Otherwise, reply "Noh". If the message is positive or is otherwise normal, also say Noh.`;
export default { export default {
@ -33,6 +36,26 @@ export default {
"Access-Control-Max-Age": "86400", "Access-Control-Max-Age": "86400",
}, },
}); });
if (body.message === "")
return new Response(
JSON.stringify({
huskable: false,
})
);
const attemptAtGettingHuskness = await env.GAMING.get(body.message, "text");
if (attemptAtGettingHuskness === "yes")
return new Response(
JSON.stringify({
huskable: true,
})
);
if (attemptAtGettingHuskness === "no")
return new Response(
JSON.stringify({
huskable: false,
})
);
const resp = await env.AI.run("@cf/meta/llama-3.1-8b-instruct", { const resp = await env.AI.run("@cf/meta/llama-3.1-8b-instruct", {
max_tokens: 5, max_tokens: 5,
messages: [ messages: [
@ -46,7 +69,7 @@ export default {
}, },
], ],
}); });
await env.GAMING.put(body.message, (resp as any).response.includes("Husk") ? "yes" : "no");
return new Response( return new Response(
JSON.stringify({ JSON.stringify({
huskable: (resp as any).response.includes("Husk"), huskable: (resp as any).response.includes("Husk"),

View file

@ -74,9 +74,9 @@ binding = "AI"
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs. # Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
# [[kv_namespaces]] [[kv_namespaces]]
# binding = "MY_KV_NAMESPACE" binding = "GAMING"
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" id = "7c8704912fcc44f3856384a44b79ec84"
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service. # Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates # Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates