Readme

Quick AI web search via email (useful for apple watch)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// A dumb search engine I can use from my apple watch by emailing a question.
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 🤖" });
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 5, 2024