export default async function ComposeEmail(data) {
const apiKey = Deno.env.get("GEMINI_API_KEY")
const prompt = {
"contents": [
{
"role": "user",
"parts": [
{
"text": "Compose an email that will be sent to me containing a summary of the following data. Make sure the email contains no placeholders. \n\n" + JSON.stringify(data)
}
]
}
],
"generationConfig": {
"temperature": 1,
"topK": 40,
"topP": 0.95,
"maxOutputTokens": 8192,
"responseMimeType": "application/json",
"responseSchema": {
"type": "object",
"properties": {
"subject": {
"type": "string"
},
"text": {
"type": "string"
},
"html": {
"type": "string"
}
}
}
}
}
const response = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" + apiKey, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(prompt)
})
const answer = await response.json()
return JSON.parse(answer.candidates[0].content.parts.map((p) => p.text).join("\n"))
}