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

Copper Contributor


I see that the official example code here is to use chat history to achieve continuous dialogue, but wouldn’t this cause the same chat history to be submitted multiple times and result in repeated token deductions? Is there a simpler way to do continuous dialogue? For example, by using dialogue ID?


 List<ChatMessage> chatMessages = new ArrayList<>();
        chatMessages.add(new ChatMessage(ChatRole.SYSTEM, "You are a helpful assistant"));
        chatMessages.add(new ChatMessage(ChatRole.USER, "Does Azure OpenAI support customer managed keys?"));
        chatMessages.add(new ChatMessage(ChatRole.ASSISTANT, "Yes, customer managed keys are supported by Azure OpenAI?"));
        chatMessages.add(new ChatMessage(ChatRole.USER, "Do other Azure AI services support this too?"));

        ChatCompletions chatCompletions = client.getChatCompletions(deploymentOrModelId, new ChatCompletionsOptions(chatMessages));


快速入门:开始通过 Azure OpenAI 服务使用 GPT-35-Turbo and GPT-4 - Azure OpenAI Service | Microsoft Learn

1 Reply
best response confirmed by Yen_Harvey (Copper Contributor)

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(

# Print the response



Here are some links you can take a look:
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