作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何从 text-davinci-003
迁移到 gpt-3.5-turbo
?
我尝试做的事情如下:
改变这个...
model: "text-davinci-003"
...对此。
model: "gpt-3.5-turbo"
此外,更改此...
const API_URL = "https://api.openai.com/v1/completions";
...对此。
const API_URL = "https://api.openai.com/v1/chat/completions";
问题是它不起作用。我将给出的代码是未修改的代码,以便任何人都可以帮助我更改哪些内容。
为什么我想要这次升级?text-davinci-003
的完成让我很恼火。就像发送“Hello”会给我一封完整的信而不是问候语。
实时示例(通过 Github 页面): https://thedoggybrad.github.io/chat/chatsystem
Github 存储库: https://github.com/thedoggybrad/chat/tree/main/chatsystem
最佳答案
您使用的是 gpt-3.5-turbo
型号。
Chat Completions API 之间存在三个主要区别(即 GPT-3.5 API)和 Completions API (即 GPT-3 API)。
https://api.openai.com/v1/completions
https://api.openai.com/v1/chat/completions
prompt
参数(Completions API)已替换为 messages
参数(Chat Completions API)response.choices[0].text.trim()
response.choices[0].message.content.trim()
试试这个:
const getChatResponse = async (incomingChatDiv) => {
const API_URL = "https://api.openai.com/v1/chat/completions"; /* Changed */
const pElement = document.createElement("p");
// Define the properties and data for the API request
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: `${userText}`}], /* Changed */
max_tokens: 2048,
temperature: 0.2,
n: 1,
stop: null
})
}
// Send POST request to API, get response and set the reponse as paragraph element text
try {
const response = await (await fetch(API_URL, requestOptions)).json();
pElement.textContent = response.choices[0].message.content.trim(); /* Changed */
} catch (error) { // Add error class to the paragraph element and set error text
pElement.classList.add("error");
pElement.textContent = "Oops! Something went wrong while retrieving the response. Please try again.";
}
// Remove the typing animation, append the paragraph element and save the chats to local storage
incomingChatDiv.querySelector(".typing-animation").remove();
incomingChatDiv.querySelector(".chat-details").appendChild(pElement);
localStorage.setItem("all-chats-thedoggybrad", chatContainer.innerHTML);
chatContainer.scrollTo(0, chatContainer.scrollHeight);
}
关于openai-api - NodeJS 中的 OpenAI API : How do I migrate from text-davinci-003 to gpt-3. 5-turbo?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76411359/
我是一名优秀的程序员,十分优秀!