如何使用openai-node请求聊天响应?



我正在使用节点包,试图让它回答标题+正文的通用问题(注意:不是堆栈溢出问题)。虽然我不知道我该怎么"聊天"请求GPT3。我发现最接近的是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}`,
temperature: 0.9
});

然而,像预期的那样,这不会给出一个答案,而是用一个额外的句子来扩展问题。我如何调用API来做https://chat.openai.com/chat之类的事情?在那里,我的问题将得到一个很好的多行回答,但我不明白如何使用他们的API复制它。

实际上createCompletion是您正在寻找的方法,但您需要稍微调整一下。试试这个:

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
});

样品问题

我有一个数字数组,比如

const numbers = [1,2,3,4,5,6,7,8,9把它分成一定长度的块?比如:

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]]怎么做?

样本回答

您可以使用Array.prototype.slice()方法创建块算法。slice()方法有两个参数开始索引和结束索引,并返回一个新数组包含两者之间的原始数组中的元素指数。

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

数组,并使用slice()方法创建一个新的数组包含两者之间的原始数组中的元素指数。

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]]
```

最新更新