-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoke.ts
More file actions
28 lines (20 loc) · 835 Bytes
/
joke.ts
File metadata and controls
28 lines (20 loc) · 835 Bytes
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
import type { HandlerEvent } from "@netlify/functions";
const { GoogleGenerativeAI } = require("@google/generative-ai");
require("dotenv").config();
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
const handler = async (event: HandlerEvent) => {
const popularity = parseInt(
event.queryStringParameters?.popularity || "50",
10
);
const prompt = `Write a funny quote, under 100 characters, about popularity on a scale from 0 to 100, where 0 is the least popular and 100 is the most. The quote should describe someone at ${popularity}, omit the popularity value.`;
const result = await model.generateContent(prompt);
return {
statusCode: 200,
body: result.response.text(),
};
};
module.exports = {
handler,
};