you love
This commit is contained in:
parent
ca0ffa5598
commit
cc9544dec5
1 changed files with 67 additions and 1 deletions
68
src/index.ts
68
src/index.ts
|
@ -1,5 +1,71 @@
|
|||
export interface Env {
|
||||
AI: Ai;
|
||||
}
|
||||
|
||||
const prompt = `You are HuskBot. Reply "Husk" if the message matches one of these:
|
||||
Contains "veeee 😭" or variants
|
||||
Mentions Nix or NixOS positively
|
||||
Is racist, misogynist, homophobic, transphobic, etc.
|
||||
Mentions betterdiscord
|
||||
Talks about Nettspend
|
||||
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.`;
|
||||
|
||||
export default {
|
||||
async fetch(request, env, ctx): Promise<Response> {
|
||||
return new Response("Hello World!");
|
||||
try {
|
||||
const body: any = await request.json();
|
||||
if (request.method === "OPTIONS") {
|
||||
return new Response(null, {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (!body.message)
|
||||
return new Response("i sharted", {
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
},
|
||||
});
|
||||
const resp = await env.AI.run("@cf/meta/llama-3.1-8b-instruct", {
|
||||
max_tokens: 5,
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: prompt,
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: body.message,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
huskable: (resp as any).response.includes("Husk"),
|
||||
}),
|
||||
{
|
||||
headers: {
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
},
|
||||
}
|
||||
);
|
||||
} catch {
|
||||
return new Response("i sharted", {
|
||||
// @ts-ignore
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "GET,HEAD,POST,OPTIONS",
|
||||
"Access-Control-Max-Age": "86400",
|
||||
});
|
||||
}
|
||||
},
|
||||
} satisfies ExportedHandler<Env>;
|
||||
|
|
Loading…
Reference in a new issue