From the course: Hands-On OpenAI API: Building a Real-World Solution

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Creating a new conversation thread and adding a message

Creating a new conversation thread and adding a message - OpenAI API Tutorial

From the course: Hands-On OpenAI API: Building a Real-World Solution

Creating a new conversation thread and adding a message

- [Instructor] Now, we're ready to create a new thread. A thread represents a conversation that includes messages created by both the user and the model. In other words, when you as a user send a message, the model will respond with a message in the same thread as your original message. This process is similar to creating a new chat in ChatGPT. Let's see how this is done. Let's create a new variable and let's name it thread. And then, let's invoke client_beta. And then threads. And here we have a couple of functions. The first one is create. And the other one allows me to create the thread and execute it right away. In this case, I'm going to use create, since I want to add messages in this handle main menu option function. So here, let's do the following, client.beta.threads, and then I'm going to add a new message. We do that by executing create. And here, I need to pass the ID of the thread in this case is thread.id. And then, the role, in this case is user. That is actually the…

Contents