1
Create an assistant
We’ll start by taking a look at the Assistant API
reference and define our
assistant:Let’s break this down:
model
- We’re using the OpenAI GPT-4 model, which is better at function calling.messages
- We’re defining the assistant’s instructions for how to run the call.functions
- We’re providing a addTopping function with a topping parameter. The assistant can call this during the conversation to add a topping. We’re also adding goToCheckout, with an empty parameters object. The assistant can call this to redirect the user to checkout.firstMessage
- This is the first message the assistant will say when the user starts the call.
2
Set up the Web SDK
We’ll follow the
README
for the Web SDK to get it installed.We’ll then get our Public Key from the Vapi Dashboard and initialize the SDK:3
Add the call buttons
We’ll add a button to the page that starts the call when clicked:
4
Handle call status events
5
Handle speaking events
6
Handle transcription events
All messages send to the Server URL, including
transcript
and function-call
messages, are also sent to the client as message
events. We’ll need to check the type
of the message to see what type it is.7
Handle function call events
8
Order your pizza!
You should now have a working pizza ordering assistant! 🍕