(req, res)
| 9 | ); |
| 10 | |
| 11 | const handler = async (req, res) => { |
| 12 | const { url, tweetCount } = req.body; |
| 13 | |
| 14 | const article = await extract(url); |
| 15 | |
| 16 | if (!article.title || !article.content) { |
| 17 | res.send(400).text("Can't extract article"); |
| 18 | } |
| 19 | |
| 20 | const cleanContent = stripHtml(article.content); |
| 21 | |
| 22 | const completion = await openai.createCompletion({ |
| 23 | model: "text-davinci-003", |
| 24 | prompt: `You are a blogger trying to promote their latest article on social media. The title is "${article.title}". Write a twitter thread summarizing the following text in ${tweetCount} numbered tweets: ${cleanContent}`, |
| 25 | temperature: 0.4, |
| 26 | max_tokens: 800, |
| 27 | best_of: 2, |
| 28 | }); |
| 29 | |
| 30 | res.status(200).send(completion.data.choices[0].text.trim()); |
| 31 | }; |
| 32 | |
| 33 | export default handler; |
nothing calls this directly
no outgoing calls
no test coverage detected