forked from Jinksi/gpt-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product-description.ts
50 lines (42 loc) · 1.56 KB
/
product-description.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import { OpenAIChat } from 'langchain/llms'
const model = new OpenAIChat({ modelName: 'gpt-3.5-turbo', temperature: 0.9 })
function getProductDescriptionPrompt({
title,
description,
tone,
targetAudience,
}: ProductDescriptionRequestProps) {
let prompt = `
I want you to act as a marketing content creator.
You will need to create engaging and informative content for creating product descriptions on ecommerce websites.
Please write product descriptions for ecommerce websites, based on brief user-provided descriptions.
The tone of voice used for the product descriptions should be ${tone}.
The product descriptions should target ${targetAudience}.
No specific guidelines or formatting requirements need to be followed.
Product title: "${title}"
Product description: "${description}"
`
return prompt
}
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<ProductDescriptionResponseProps>
) {
const body: ProductDescriptionRequestProps = req.body
let {
title = 'Mega Rainbow Unicorn Onesie',
description = 'Colorful, comfortable, warm, fuzzy and magical.',
tone = 'friendly and conversational',
targetAudience = 'a general audience',
} = body
const prompt = getProductDescriptionPrompt({
title,
description,
tone,
targetAudience,
})
const modelResponse = await model.call(prompt)
res.status(200).json({ description: modelResponse.trim() })
}