Aside: few shot approach II
AboutCommentsNotes
Aside: few shot approach II
Expand for more info
index.js
run
preview
console
import { Configuration, OpenAIApi } from "openai";
import { process } from './env';

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);

document.getElementById("submit-btn").addEventListener("click", () => {
const productName = document.getElementById("name").value;
const productDesc = document.getElementById("desc").value;
const productTarget = document.getElementById("target").value;
getCopySuggestion(productName, productDesc, productTarget);
})


async function getCopySuggestion(productName, productDesc, productTarget) {
const response = await openai.createCompletion({
model: "text-davinci-003",

/*
Challenge:
1. Add a second example here. Be sure to make it similar in design to the first.
2. Remember to use separators
*/


prompt: `Use a product name, a product description and a target market to create advertising copy for a product.
###
product name: Flask Tie
product description: A tie with a pouch to hold liquids and a straw to drink through
product traget market: office workers
advertising copy: Are you tired of having to worry about how much to drink throughout the day? With the Flask Tie, you can stay hydrated on-the-go! Our unique tie features a pouch that enables you to securely hold and sip your favorite drinks with the built-in straw! The water cooler is history! Long live Flask Tie!
###
product name: ${productName}
product description: ${productDesc}
product traget market: ${productTarget}
advertising copy:
`,
max_tokens: 100,
});
document.getElementById('ad-output').insertAdjacentText('beforeend', response.data.choices[0].text.trim())
document.getElementById('ad-input').style.display = 'none'
document.getElementById('ad-output').style.display = 'block'
console.log(response)
}
Console
{data:
{id:
"cmpl-6mkGFEBuZgAtuiqkRFowYm52gkFKz"
, object:
"text_completion"
, created:
1677075591
, model:
"text-davinci-003"
, choices:
[
{text:
" Treat your kids to the deliciousness of seafood without the guilt of overfishing with our yummy, new vegan Fish Cream! Kids under 12 will love the unique taste of fish with the creamy goodness of ice cream, all while the whole family can feel great knowing they're supporting eco-friendly fishing practices! Try Vegan Fish Cream today and make a splash with your kids!"
, index:
0
, logprobs:
null
, finish_reason:
"stop"
}
]
, usage:
{prompt_tokens:
172
, completion_tokens:
77
, total_tokens:
249
}
}
, status:
200
, statusText:
""
, headers:
{cache-control:
"no-cache, must-revalidate"
, content-length:
"638"
, content-type:
"application/json"
}
, config:
{transitional:
{silentJSONParsing:
true
, forcedJSONParsing:
true
, clarifyTimeoutError:
false
}
, adapter:
xhrAdapter(e)
, transformRequest:
[
transformRequest(e,t)
]
, transformResponse:
[
transformResponse(e)
]
, timeout:
0
, xsrfCookieName:
"XSRF-TOKEN"
, xsrfHeaderName:
"X-XSRF-TOKEN"
, maxContentLength:
-1
, maxBodyLength:
-1
, validateStatus:
validateStatus(e)
, headers:
{Accept:
"application/json, text/plain, */*"
, Content-Type:
"application/json"
, User-Agent:
"OpenAI/NodeJS/3.1.0"
, Authorization:
"Bearer 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"
}
, method:
"post"
, data:
"{"model":"text-davinci-003","prompt":"Use a product name, a product description and a target market to create advertising copy for a product.\n ###\n product name: Flask Tie\n product description: A tie with a pouch to hold liquids and a straw to drink through\n product traget market: office workers\n advertising copy: Are you tired of having to worry about how much to drink throughout the day? With the Flask Tie, you can stay hydrated on-the-go! Our unique tie features a pouch that enables you to securely hold and sip your favorite drinks with the built-in straw! The water cooler is history! Long live Flask Tie!\n ###\n product name: Vegan Fish Cream\n product description: Fish flavoured vegan ice cream\n product traget market: kids under 12\n advertising copy: \n ","max_tokens":100}"
, url:
"https://api.openai.com/v1/completions"
}
, request:
XMLHttpRequest {}
}
,
/index.html
-2:54