On a playground, each response is linked to all (most) previous prompts, but in an API call openai.Completions.create(), every response is standalone, which makes it pretty much useless for meaningful conversation. On probing further AI assistant revealed the following. But this doesn’t work. Anyone struggling with this problem?
Open.Conversation.create()
To retain the conversation context across API calls, you can use the openai.Conversation.create API endpoint instead. This endpoint allows you to specify a conversation_id parameter in the API request and retain the conversation context across multiple API calls.
Here is an example of how you can use the openai.Conversation.create API endpoint to retain the conversation context:
import openai
Set the conversation identifier
conversation_id = "my-conversation-id"
Set the API key
openai.api_key = "YOUR_API_KEY"
Send the first message
response = openai.Conversation.create(
engine="text-davinci-002",
prompt="What is the capital of France?",
max_tokens=1024,
temperature=0.5,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
conversation_id=conversation_id
)
Print the response
print(response["replies"][0]["text"])
Send the second message
response = openai.Conversation.create(
engine="text-davinci-002",
prompt="What is the currency of France?",
max_tokens=1024,
temperature=0.5,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
conversation_id=conversation_id
)
Print the response
print(response["replies"][0]["text"])
This will ensure that the Assistant retains the conversation context across API calls and can provide appropriate responses based on the previous messages in the conversation.
I hope this helps! Let me know if you have any other questions.