It would make sense to use the phone number here, but I would just use a timestamp, because I would be the only one calling it anyway. And then in the WebSocket configuration, I just have a callback when the socket is open. When it's closed, let's format it a bit. And then the interesting part happens here, when a message comes in. I pass the JSON payload, and then when the message is of type prompt, which it will mostly be. Anyway, I log this to the console, and for now, let's have a hard-coded answer to say that's a great question. And then I log it to the console, and I just stream it back. And what I also do is I log the other types so you see them, but we don't have to worry about them for now.
Okay, let's give it a run. I run my server. I expose this port to the internet, and if I go over here to my configuration, you see whenever a call comes into a phone number, it connects to my WebSocket server. This is the I use 11 labs for text-to-speech. This particular idea of the voice, and this is the starting sentence. Let's call it, and let's hope it works. Is the audio? Let me check. That's a great question. Hey, what's the capital of France? That's a great question. You see, I always get the same response back. Why? Because I don't do anything here. I just say return a static response, but you saw how fast the latency was. So, if I look at the logs, you see the text-to-speech, and speech-to-text happened instantly. Now, let's actually involve some AI here, and if I drill down into that, that's auto-imported.
You see, what do I do here? Well, I have an if statement to see do I already know this conversation ID. If I don't know it, I just use the GPT4 or mini model. I add a system prompt, and the prompt of the user. I add a web search tool, and I make sure to store the history on the server side at OpenAI, and then if the response comes back, I save it. So, when I ask another question the next time, the if statement is triggered here, and then I can refer to the previous conversation, so I don't have to carry on that messages array all the time. I just have to add the most recent prompt. Let's try that again. I restart the server.
Comments