Im using the node package, trying to get it to answer generic question with title + body. Note, NOT stackoverflow questions. Though I cant see how Im supposed to do a "chat" request to GPT3. The closest I found is completion:
const completion = await openai.createCompletion({
model: 'text-davinci-003',
prompt: `Please provide an answer to the question below.\n#${question.title}\n${question.text}`,
开发者_Go百科 temperature: 0.9
});
However, like expected this will not give an answer rather extend the question with an extra sentence or so. How can I call the API to do something like https://chat.openai.com/chat ? There my question will get a nice multiline answer, but I cant understand how to replciate it using their API.
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. Theslice()
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]] ```
精彩评论