对接ChatGPT时如何保证同一个用户会话的连惯性

闪电发卡2年前ChatGPT1574
要保证对接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就能够识别这是同一个用户的连续问题,并能够保证回答的连贯性。



闪电发卡ChatGPT产品推荐:

ChatGPT独享账号:https://www.chatgptzh.com/post/86.html

ChatGPT Plus共享账号:https://www.chatgptzh.com/post/319.html

ChatGPT Plus独享账号(购买充值代充订阅):https://www.chatgptzh.com/post/306.html

ChatGPT APIKey购买充值(直连+转发):https://www.chatgptzh.com/post/305.html

ChatGPT Plus国内镜像逆向版:https://www.chatgptzh.com/post/312.html

ChatGPT国内版(AIChat):https://www.chatgptzh.com/post/318.html


相关文章

从人工智能到电商成功:ChatGPT的多种应用

大家好,欢迎来到我的博客。今天我们来聊聊一个非常热门的话题——ChatGPT。你可能已经听说过ChatGPT,但你知道它不仅仅是一款聊天机器人吗?事实上,ChatGPT在各个领域都有着广泛的应用,从人...

ChatGPT4.0账号购买后如何激活和使用?详细教程

闪电发卡ChatGPT产品推荐:ChatGPT独享账号:https://www.chatgptzh.com/post/86.htmlChatGPT Plus独享共享账号购买代充:https://www...

购买ChatGPT Pro共享账号的最佳平台推荐

闪电发卡ChatGPT和Claude产品推荐: ChatGPT Pro共享账号 ChatGPT Pro独享账号 ChatGPT独享账号 Claude Pr...

ChatGPT 4.0代充值:安全快捷的操作攻略

闪电发卡ChatGPT和Claude产品推荐: ChatGPT Pro共享账号 ChatGPT Pro独享账号 ChatGPT独享账号 Claude Pr...

怎样使用Sora?Sora产品介绍和使用教程攻略

怎样使用Sora?Sora产品介绍和使用教程攻略

Sora 是什么? 2024年2月16日,OpenAI 在其官网上面正式宣布推出文本生成视频的大模型 Sora: openai.com/sora (PS:目前 openai 官方还未开放 so...

GPT-4.0购买常见问题解答:新手入门必看

闪电发卡ChatGPT产品推荐:ChatGPT独享账号:https://www.chatgptzh.com/post/86.htmlChatGPT Plus独享共享账号购买代充:https://www...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。