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.

Implementing logging in the Web API

Implementing logging in the Web API

- [Instructor] In this video, we're going to implement logging logic in the service. This can come in handy when inspecting the request data sent by the service clients such as the GPT application. To do this, let's import the logging module. So we have the module and then let's configure the logging level. So logging.basicConfig, and we're going to use say INFO just like this. And now I need a way to read the request data since I'm interested in a particular header. So let's import both FastAPI and the request class from the FastAPI module. So here, let's modify the function and let's specify request is going to be request. And now I'm ready to read the headers. I'm interested in a particular header, which is Openai-Conversation-Id that the GPT application will send. So I can do something like headers and then get and the name of the header Openai-Conversation-Id. Okay, and let's put this in conversation_id. Okay, so now I can validate if this has a value. Then let's use logging.info…

Contents