Using Chat Completions API plainly will give output with additional texts like your previous result. You can probably just remove them when you parse the result.
Another way, is to use function call. Using this function:
{
name: "how_to",
description: "Generate steps to achieve user input",
parameters: {
type: "object",
properties: {
steps: {
type: "array",
items: {
type: "string",
}
}
},
required: ["steps"]
}
}
To call the API:
const messages = [{ role: 'user', content: user_prompt }]
const result = await openai.createChatCompletion({
messages,
model: 'gpt-3.5-turbo-0613',
temperature: 0,
functions,
})
Using this user prompt: build swimming pool
Will give this result:
{
role: 'assistant',
content: null,
function_call: {
name: 'how_to',
arguments: '{\n' +
' "steps": [\n' +
' "1. Determine the location and size of the swimming pool.",\n' +
' "2. Obtain any necessary permits or approvals from local authorities.",\n' +
' "3. Excavate the area for the pool, ensuring it is level and free from any obstructions.",\n' +
' "4. Install the pool shell or structure, which can be made of concrete, fiberglass, or vinyl.",\n' +
' "5. Connect the necessary plumbing and electrical systems for the pool.",\n' +
' "6. Install the pool liner or finish the interior surface of the pool.",\n' +
' "7. Fill the pool with water and check for any leaks or issues.",\n' +
' "8. Install any additional features such as a pool heater, lighting, or a filtration system.",\n' +
' "9. Landscaping around the pool area to enhance its appearance.",\n' +
' "10. Regularly maintain and clean the pool to ensure its longevity and safety."\n' +
' ]\n' +
'}'
}
}