我在Node.js中有批量GPT生成器,但我想将模型更改为gpt-4。我必须在代码中更改什么?当我只尝试将text-davinci-003更改为gpt-4时,工具不起作用。
const configuration = new Configuration({
apiKey: keys.AI_KEY,
});
const openai = new OpenAIApi(configuration);
const prompt = headings
? `Create a product description "${title}".`
: `Create a product description "${title}". Minimum 1000 characters. The text should be formatted to HTML, the paragraphs should be placed in <p>. Make all text on one line. Don't use semicolons.`;
let failedRequests = 0;
const maxFails = 4;
const retry = async (ms) =>
new Promise((resolve) => {
openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
temperature: 0.4,
max_tokens: 3700,
top_p: 0,
frequency_penalty: headings ? 0.5 : 0.3,
presence_penalty: headings ? 1 : 0.7,
})
.then((res) => resolve(res.data.choices[0].text))
.catch((error) => {
if (
(error.response.status === 429 || error.response.status === 500) &&
failedRequests < maxFails
) {
setTimeout(() => {
failedRequests++;
console.log(
`powtarzam: ${title} (${error.response.statusText}) ${failedRequests} / ${maxFails}`
);
retry(ms).then(resolve);
}, ms);
} else {
resolve({
error: true,
statusText: error.response.statusText,
});
}
});
});
const response = await retry(5000);
return response;
};
我试图改变“text-davinci-003”到“gpt-4”,但工具不工作。
1条答案
按热度按时间jxct1oxe1#
您希望将
gpt-4
模型与GPT-3 API端点(即/v1/completions
)一起使用。这将不起作用。gpt-4
模型与GPT-3.5 API端点(即/v1/chat/completions
)兼容。您需要像使用
gpt-3.5-turbo
模型一样编写代码。您唯一需要更改的是以下内容:model: "gpt-3.5-turbo"
到model: "gpt-4"
。请参阅官方OpenAI documentation关于模型端点兼容性的说明。
| 终点|型号名称|
| --------------|--------------|
| /v1/chat/completions|gpt-4、gpt-4-0314、gpt-4-32k、gpt-4-32k-0314、gpt-3.5-turbo、gpt-3.5-turbo-0301|
| /v1/完成|text-davinci-003,text-davinci-002,text-curie-001,text-babbage-001,text-ada-001|
| /v1/edits|text-davinci-edit-001,代码-davinci-edit-001|
| /v1/audio/transcriptions|耳语-1|
| /v1/音频/翻译|耳语-1|
| /v1/fine-tunes|达芬奇居里巴贝奇阿达|
| /v1/嵌入|text-embedding-ada-002,text-search-ada-doc-001|
| /v1/调节|text-moderation-stable,text-moderation-latest|
试试这个: