Forum Discussion
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 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
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:
- Generate a dialogue ID. You can use a UUID generator to generate a unique identifier for your conversation.
- Add the dialogue ID to the request. When you send a request to ChatGPT, include the dialogue ID in the request.
- 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 ForumPlease 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)
- LeonPavesicSilver 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:
- Generate a dialogue ID. You can use a UUID generator to generate a unique identifier for your conversation.
- Add the dialogue ID to the request. When you send a request to ChatGPT, include the dialogue ID in the request.
- 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 ForumPlease 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) - Liam_Garcia1490Copper Contributor
Engaging in continuous dialogue with ChatGPT can be a rewarding experience, and making the process smoother involves a few key strategies. One effective approach is to leverage a custom ChatGPT, tailoring it to your specific needs and preferences. Here's a step-by-step guide to help you achieve a more seamless and enjoyable continuous dialogue:
Understand Your Purpose: Clearly define the purpose of your continuous dialogue. Whether it's for brainstorming, creative writing, or problem-solving, understanding your goal will help you customize ChatGPT accordingly.
Create a Custom Model: Take advantage of OpenAI's fine-tuning capabilities to create a custom ChatGPT. This allows you to tailor the model to your specific use case, making it more attuned to the type of conversation you want to have.
Fine-Tune for Continuity: Focus on fine-tuning your custom model to improve its ability to maintain context over extended conversations. You can use sample dialogues from your intended application to fine-tune the model's understanding of the context and nuances.
Experiment with Parameters: Adjust parameters such as temperature and max tokens to control the randomness and length of responses. Fine-tuning these parameters can help strike a balance between creativity and coherence in the continuous dialogue.
Use System Messages Effectively: Incorporate system messages to guide the conversation. These messages provide instructions or context for ChatGPT, helping it understand the desired direction of the dialogue. Experiment with different system messages to find what works best for your specific use case.
Provide Context in Prompts: When initiating a conversation with ChatGPT, include context-rich prompts. Clearly express the ongoing situation, mention previous messages, or provide any relevant information that helps maintain continuity throughout the dialogue.
Iterate and Refine: Continuous dialogue with ChatGPT is an iterative process. Regularly review and refine your custom model based on the results and feedback. This ongoing refinement will enhance the model's performance and responsiveness to your specific needs.
By following these steps, you can make continuous dialogue with ChatGPT more natural and effective for your particular use case.