Oct 10 2023 03:48 AM - edited Oct 10 2023 03:53 AM
我看到这里的官方示例代码是通过添加聊天历史记录来进行连续对话的,但是这样的话相同的聊天记录不就会多次重复提交导致重复扣除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
Oct 12 2023 02:36 AM
SolutionHi @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:
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)