英文:
How to maintain context with OpenAI gpt-3.5-turbo API?
问题
我认为用户参数正在执行这个任务。但它不起作用。
英文:
I thought the user parameter is doing this job. But it doesn’t work.
答案1
得分: 7
你需要重新提供之前的回应以保持上下文。(用户参数仅用于OpenAI监控滥用情况)。请记住,这是一个完成型AI,意味着它只能接受输入并提供输出。为了保持上下文,你需要输入上下文。
另外,请注意,新模型“gpt-3.5-turbo”处理信息的方式与Davinci模型有所不同。
Davinci模型的输入方式如下:
// 导入和配置...
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
temperature: 0,
max_tokens: 7,
});
而gpt-3.5-turbo模型的输入方式如下:
// 导入和配置...
const response = await openai.createCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "user", content: "Say this is a test"},
],
temperature: 0,
});
因此,它有些不同。如果你想重新提供上下文,你需要在“messages”中创建一个输入字段,类似于这样...
// 导入和配置...
const message = "<user input>"
const context = "<user previous messages if any, else empty>"
const response = await openai.createCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "system", content: `${context}`},
{role: "user", content: `${message}`},
],
temperature: 0,
});
“system”角色用于上下文,这样gpt就知道首要回应用户的输入而不是系统的输入。这也可以用于提前介绍用户提示的字段。
希望这有所帮助。
英文:
You need to refeed your previous responses to maintain context. (The user param is only for OpenAI to monitor abuse). Remember it is a completion AI, meaning that it can only take input and give output. To maintain context, you need to input the context.
Also, keep in mind that the new model, gpt-3.5-turbo
processes info differently than the Davinci model.
Davinci input is like this:
//import and configure...
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Say this is a test",
temperature: 0,
max_tokens: 7,
});
while the gpt-3.5-turbo model is like this:
//import and configure...
const response = await openai.createCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "user", content: "Say this is a test"},
],
temperature: 0,
});
So it's a little different. If you want to refeed for context, you need to make an input field in the "messages" - something like this...
//import and configure...
const message = "${<user input>}"
const context = "${<user previous messages if any, else empty>}"
const response = await openai.createCompletion({
model: "gpt-3.5-turbo",
messages: [
{role: "system", content: `${context}`},
{role: "user", content: `${message}`},
],
temperature: 0,
});
The "system" role is for the context, so gpt knows to respond to the user input primarily and not the system input. That can also be a useful field for prefacing user prompts fyi.
Hope that helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论