How can I call 3rd party API in the middle of the conversation?

Hi there,
How can I call 3rd party API in the middle of the conversation?
so let’s say in our pizza bot example, as soon as we collect the data for the first pizza, we want to generate the JSON and call our order API to place the order and then go back and tell the customer:
“we placed the first order, do you need another one?”
or something like this

@deeplearning @DeepLearning.AI-Team @deeplearningAI

Thanks for your time

Conversations with chatgpt is stateless. Once chatgpt responds to your prompt, the conversation is considered as over. You can do whatever you want in your application code.

I understand that, so maybe I’m not using it in the correct way then. so I’m using it in Python, not the notebook.
As a result, I have a while loop ( if it’s not the best way, what is your suggestion?) to keep asking the questions, but in our pizza ordering, it keeps asking the question and I don’t know when I have all the details for the calling my order API to create the order. does it make sense what I’m saying?

Am I doing it correctly? Is there any better way of doing it?

basically, I want to make it more dynamic to communicate to other APIs, when all the necessary info is provided via customer, while not interrupting the conversation.

Thanks for your help

Using a while loop is a valid approach to ask follow up questions to get complete order information from the customer. You can break out of the while loop to place the order using an API and provide response to the customer about the order status.

Thanks for your reply.
Exactly, I need to break out of the while loop, but the problem is I don’t know I should do that! I

if I use the get_completion() that we have in the course (which is not conversational), I can make my prompt somehow give me the details when it has all of them in JSON format, as it is not in the loop and it’s kind of one-time thing.

but now that I’m using get_completion_from_messages() in a loop, it just returns the message, and I can’t modify that response to include other information

At least it’s my understanding!

any idea? any sample code you might have?

I don’t have a python example. The message you get from openai api call is a python string. You can do anything with it.

If this is unclear, please click my name and message your python file as an attachment.