i would like to be able to do something like this:
await openai_ws.send(json.dumps({
"event_id": "event_234",
"type": "response.create",
"response": {
"modalities": ['audio', 'text'],
"instructions": f"THIS IS RESPONSE ONE",
"voice": "alloy",
"output_audio_format": "g711_ulaw",
"temperature": 0.7,
"max_output_tokens": 150
}
}))
# ** SOME OTHER COMPUTATIONS HERE **
await openai_ws.send(json.dumps({
"event_id": "event_234",
"type": "response.create",
"response": {
"modalities": ['audio', 'text'],
"instructions": f"THIS IS RESPONSE TWO",
"voice": "alloy",
"output_audio_format": "g711_ulaw",
"temperature": 0.7,
"max_output_tokens": 150
}
}))
but this results in an error:
{'type': 'error', 'event_id': 'event_AJY4PPmCD57vhGHLtGLXE', 'error': {'type': 'invalid_request_error', 'code': None, 'message': 'Conversation already has an active response', 'param': None, 'event_id': None}}
i can stick a
await asyncio.sleep(10)
in between the two create response blocks and it clears the error, but doesn’t give the desired behaviour (i.e. it sleeps 10 seconds BEFORE even the first response is streamed) and even if it slept X seconds between the two responses, it wouldn’t be very robust (first response can take longer or shorter than X)
My guess is that I need to monitor the server events and only submit the second message after a certain response.* event has come through, but it’s unclear to me how exactly to approach it.
Any help is appreciated.