Back

Version 19

9/29/2023
let catFact = async (request: Request): Promise<Response> => {
let cat = await fetch("https://catfact.ninja/fact");
let { fact } = await cat.json();
const prompt =
"Write a short background story about this fact and how it was known:\n\n" +
fact;
const story = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{ role: "user", content: prompt }],
temperature: 0.7,
}),
headers: {
"Authorization": "Bearer " + @yuval_dikerman.secrets.OPENAI,
"Content-Type": "application/json",
},
}).then(async (response) => {
let { choices } = await response.json();
return choices[0].text;
});
return Response.json({ story });
};
yuval_dikerman-catfact.web.val.run
Updated: October 23, 2023