gpt4 book ai didi

node.js - 如何请求与 openai-node 的聊天响应?

转载 作者:行者123 更新时间:2023-12-02 05:46:19 25 4
gpt4 key购买 nike

我正在使用 node package ,试图让它回答带有标题+正文的一般问题。注意,不是 stackoverflow 问题。虽然我看不出我应该如何向 GPT3 发出“聊天”请求。我发现最接近的是完成:

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

示例问题

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 tosplit 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?

示例答案

You can use the Array.prototype.slice() method to create a chunkalgorithm in JavaScript. The slice() method takes two arguments, thestarting index and the ending index, and returns a new arraycontaining the elements from the original array between the twoindices.

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 arraycontaining the elements from the original array between the twoindices.

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

关于node.js - 如何请求与 openai-node 的聊天响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74713579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com