Actually createCompletion
is the method you are looking for, but you need to tweak it a bit. Try this:
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Please provide an answer to the question below.\n#${question.title}\n${question.text}`,
temperature: 0,
max_tokens: 500,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.0
});
Sample question
I have an array of numbers, lets say
const numbers = [1,2,3,4,5,6,7,8,9] How can I make a method chunk to
split it up into chunks of certain length? Something like:
const numbers = [1,2,3,4,5,6,7,8,9] const chunks = chunk(numbers, 3)
// [[1,2,3], [4,5,6], [7,8,9]] How can I do that?
Sample answer
You can use the Array.prototype.slice()
method to create a chunk
algorithm in JavaScript. The slice()
method takes two arguments, the
starting index and the ending index, and returns a new array
containing the elements from the original array between the two
indices.
For example, to create a chunk algorithm that splits an array into chunks of a certain length, you could use a `for` loop to iterate over
the array and use the slice()
method to create a new array
containing the elements from the original array between the two
indices.
Here is an example of a chunk algorithm in JavaScript:
```js
function chunk(arr, size) {
const chunked = [];
for (let i = 0; i < arr.length; i += size) {
chunked.push(arr.slice(i, i + size));
}
return chunked;
}
const numbers = [1,2,3,4,5,6,7,8,9]
const chunks = chunk(numbers, 3)
// [[1,2,3], [4,5,6], [7,8,9]]
```