Playing
01. Introduction and demo

Transcript

00:00
Making requests to chat GPT and getting a response back isn't too tricky, particularly when you use something like the OpenAI PHP client.
00:08
But we're going to take this a little step further and look at streamed responses and also maintaining conversation context. So if I tell this bot something, it's
00:19
going to go ahead and remember what I say. Let's go ahead and try this out. So the way that I have set up the prompt here is that it is a friendly bot who will help with any kind of web
00:29
development problems. So let's go ahead and just say, hey. OK, so we're going to wait here. And you can see that the response here
00:35
was streamed in. Rather than waiting for that huge length of time for everything to come back, it will give this to us as it kind of types.
00:44
OK, so I'm just going to say, link me to the Laravel docs. And we'll just wait for here. And you can see that streaming in. It gives us the link.
00:53
We don't have Markdown or anything like this enabled here. So we can't click on this. But we can easily add that in later. OK, so I'm going to ask this to remember something.
01:01
So my name is Alex. And it should respond with something. And I'm just going to ask it what my name is. So what is my name?
01:11
And there we go. Great. So this doesn't happen by default when we send requests to the API.
01:16
Because of course, we send a request off. We get a response back. We don't maintain any kind of context within the conversation history.
01:23
So we're going to be adding that in as well. OK, so let's go ahead and build this. We're going to learn a huge amount about wire stream, which is incredibly useful for other situations as well.
01:34
So you can go ahead and use that for anything where you have streamed content. OK, let's go over and get everything set up and start to build this out.

Episode summary

In this intro episode, we kick things off by talking about how to interact with ChatGPT using PHP. Instead of just getting basic responses back, we're aiming for something cooler—streamed responses, where you see the reply arriving in real-time, and proper conversation context, so the bot actually remembers what you've said before.

You’ll see a demo of a friendly web development bot that can respond to your questions, remember details (like your name!), and stream its answers as they come in. We'll also touch on the fact that out-of-the-box, OpenAI's API doesn't keep track of conversation history, so we’re going to build that in.

Finally, there's a quick look at how streaming works and a mention of wire:stream—a helpful tool if you want to deal with any live, streamed content in PHP. After running through a few examples, we're ready to get everything set up and start building!

If you’re new, this episode serves as a tour of what you’ll learn and why it’s going to be useful for your own projects.

Episode discussion

No comments, yet. Be the first!