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
35
36
37
38
39
40
41
import { email } from "https://esm.town/v/std/email?v=12";
const modelName = "lg-v6";
const dictionaryUrl = `https://thesephist--prism-start-app.modal.run/models/${modelName}`;
const confidenceThreshold = 0.8;
function randomlyPickFeature(featuresAboveConfidenceThreshold) {
return featuresAboveConfidenceThreshold[Math.floor(Math.random() * featuresAboveConfidenceThreshold.length)];
}
function getFeatureLink(feature) {
const { index } = feature;
return `https://thesephist--prism-start-app.modal.run/f/${modelName}/${index}?layout=2`;
}
export default async function(interval: Interval) {
const response = await fetch(dictionaryUrl);
const { features } = await response.json();
const featuresAboveConfidenceThreshold = features.filter(
feature => feature.confidence > confidenceThreshold,
);
const randomFeature = randomlyPickFeature(featuresAboveConfidenceThreshold);
const { index, label, attributes, confidence, density } = randomFeature;
const messageSubject = `Feature of the day: ${label}`;
const messageBody = [
`Today's feature is #${index}: ${label} with a confidence score of ${confidence} and a density of ${density}.`,
``,
`${attributes}`,
``,
`Read more: ${getFeatureLink(randomFeature)}`,
].join("\n");
const payload = {
subject: messageSubject,
text: messageBody,
};
console.log(payload);
void email(payload);
}