Forum Discussion

Yen_Harvey's avatar
Yen_Harvey
Copper Contributor
Oct 10, 2023
Solved

chatgpt如何更简单的进行连续对话?How to do continuous dialogue more easily with chatgpt?

我看到这里的官方示例代码是通过添加聊天历史记录来进行连续对话的,但是这样的话相同的聊天记录不就会多次重复提交导致重复扣除token的费用吗?没有更简单的连续对话方式吗?比如通过对话ID? I see that the official example code here is to use chat history to achieve continuous dialogue, but...
  • LeonPavesic's avatar
    Oct 12, 2023

    Hi Yen_Harvey,

    o do continuous dialogue more easily with ChatGPT, you can use the dialogue ID. The dialogue ID is a unique identifier that is generated for each conversation. It can be used to track the progress of a conversation and to prevent duplicate token deductions.

    Here is a quick guide on how to use dialogue ID for continuous dialogue with ChatGPT:

    1. Generate a dialogue ID. You can use a UUID generator to generate a unique identifier for your conversation.
    2. Add the dialogue ID to the request. When you send a request to ChatGPT, include the dialogue ID in the request.
    3. Use the dialogue ID to retrieve the chat history. When you need to retrieve the chat history for a conversation, include the dialogue ID in the request.

    Here is an example of how to use dialogue ID for continuous dialogue with ChatGPT using Python:

     

     

    import openai
    
    # Generate a dialogue ID
    dialogue_id = openai.uuid.generate()
    
    # Add the dialogue ID to the request
    response = openai.ChatCompletion.create(
        model="text-davinci-002-render",
        prompt="Hello!",
        dialogue_id=dialogue_id
    )
    
    # Print the response
    print(response.choices[0].text)

     

     

    Here are some links you can take a look:
    https://platform.openai.com/docs/api-reference
    Conversation ID and Chat History ID parity - Plugin Development - OpenAI Developer Forum

    Please click Mark as Best Response & Like if my post helped you to solve your issue.
    This will help others to find the correct solution easily. It also closes the item.


    If the post was useful in other ways, please consider giving it Like.


    Kindest regards,


    Leon Pavesic
    (LinkedIn)

     

Resources