How to Manually Call a Function in the OpenAI Realtime API

6 days ago 8
ARTICLE AD BOX

I’m using OpenAI Realtime with LiveKit to have conversations with my clients. I have multiple functions that I want to call out-of-band during the interaction, so in my session.update I pass my list of tools and set tool_choice to none (so I can call them manually).

My intention is not for the model to call tools automatically. Instead, I want to explicitly trigger a specific function using response.create with tool_choice.

This is my function, and this is an example of my session update for initialization.

CaptureOrderInfo = {
“type”: “function”,
“name”: “CaptureOrderInfo”,
“description”: “Extract order details mentioned in the conversation.”,
“parameters”: {
“type”: “object”,
“properties”: {
“order_details”: {
“type”: “string”,
“description”: “What the customer ordered”
},
“phone_number”: {
“type”: “string”,
“description”: “Customer phone number”
},
“discount_coupon”: {
“type”: “string”,
“description”: “Coupon or discount mentioned”
}
},
“required”: [“phone_number”]
}
}

and this is how I update my session

{ "type": "session.update", "session": { "type": "realtime", "model": "gpt-realtime", "audio": { "input": { "turn_detection": {"type": "server_vad"}, }, "output": { "voice": VOICE } }, "instructions": f"{Main prompt}" "tools": [CaptureOrderInfo], "tool_choice": "none", } }

However, when I request an out-of-band response with my function (which has already been initialized with my main prompt), I always get an empty answer. For example, the response returns {}

This is how I send my OOB manual fucntion call

{
“type”: “response.create”,
“response”: {
“conversation”: “none”,
“output_modalities”: [“text”],
“tools”: [“CaptureOrderInfo”],
“metadata”: {
“topic”: “CaptureOrderInfo”
},
“tool_choice”: {
“type”: “function”,
“name”: “CaptureOrderInfo”
}
}
}

Nonetheless I always get:

{
“type”: “response.done”,
“response”: {
“object”: “realtime.response”,
“status”: “completed”,
“status_details”: null,
“output”: [
{
“type”: “message”,
“status”: “completed”,
“role”: “assistant”,
“content”: [
{
“type”: “output_text”,
“text”: “{}”
}
]
}
],
“conversation_id”: null,
“output_modalities”: [“text”],
“max_output_tokens”: “inf”,
“audio”: {

}
},
“metadata”: {
“topic”: “CaptureOrderInfo”
}
}
}
I would appreciate it if someone could explicitly correct me on how to properly request the execution of my function in the way I intend.

Read Entire Article