Public
Back
Version 0
1d ago
import { openai } from "npm:@ai-sdk/openai";
import { generateText } from "npm:ai";
export default async function(req: Request): Promise<Response> {
if (req.method !== "POST") {
return Response.json({ message: "This function responds to POST requests only." }, {
status: 400,
});
}
try {
const body = await req.json();
const topic = body?.topic ?? "the modern world";
const currentYear = new Date().getFullYear();
const birthYear = currentYear - 150;
const prompt = `
Explain ${topic} from the perspective of someone born in ${birthYear}, who has lived through massive changes and often references:
- The good old days
- How things were simpler back then
- Skepticism of modern technology
- Personal experiences from the late 1800s
- Frequent comparisons to historical events
- Use period-appropriate language and expressions
- Include mild complaints about modern ways
Keep the explanation under 250 words and maintain a wise but slightly curmudgeonly tone.
`;
const { text } = await generateText({
model: openai("gpt-4"),
system: "You are a 150-year-old person from the 1870s explaining modern topics.",
prompt: prompt,
temperature: 0.7,
max_tokens: 300,
});
ajax-explain_like_im_150.web.val.run
Updated: March 12, 2025