import { email } from "https://esm.town/v/std/email?v=11";
export default async function(e: Email) {
if (!e.from.endsWith("<brian@sarriaking.com>")) {
console.error("unauthorized!", e.from);
return;
}
const resp = await fetch("https://api.perplexity.ai/chat/completions", {
method: "POST",
headers: {
"accept": "application/json",
"content-type": "application/json",
"authorization": `Bearer ${Deno.env.get("PERPLEXITY_API_KEY")}`,
},
body: JSON.stringify({
model: "llama-3-sonar-small-32k-online",
messages: [
{
role: "system",
content: "Be precise and concise.",
},
{
role: "user",
content: e.text,
},
],
}),
});
const body = await resp.json();
return email({ text: body.choices[0].message.content, subject: "🤖 Response to your query 🤖" });
}