要保证对接ChatGPT API时是同一个用户的连续问题,可以使用API返回的completion对象中的conversation_id属性来实现。conversation_id是一个字符串,可以唯一标识一个会话(即一个用户的连续问题)。
具体地说,当您第一次发送请求时,可以不指定conversation_id,API将自动生成一个新的conversation_id并返回。当您想要继续与同一用户的会话时,需要将上一次请求中返回的conversation_id作为当前请求的参数之一。
例如,您第一次发送请求时,请求可以这样写:
{
"model": "davinci",
"prompt": "Hello, how can I help you today?",
"temperature": 0.5,
"max_tokens": 50
}
API返回的completion对象中包含conversation_id属性,例如:
{
"id": "cmpl-1234567890",
"object": "text_completion",
"created": 1619692352,
"model": "davinci",
"prompt": "Hello, how can I help you today?",
"choices": [
{
"text": "I'm feeling a bit down lately. Can you help me figure out why?",
"index": 0,
"logprobs": null,
"finish_reason": "length"
}
],
"conversation_id": "conv-1234567890"
}
接下来,当您想要继续与同一用户的会话时,可以将上一次请求中返回的conversation_id作为当前请求的参数之一:
{
"model": "davinci",
"prompt": "I'm feeling a bit down lately. Can you help me figure out why?",
"temperature": 0.5,
"max_tokens": 50,
"conversation_id": "conv-1234567890"
}
这样,API就能够识别这是同一个用户的连续问题,并能够保证回答的连贯性。