Spaces:
Sleeping
Sleeping
added dspy, to allow .mkv files, upload multiple slides and notebooks, remove base name matching in mentor materials
a4af32a
| start_time end_time speaker transcript | |
| 1.84 82.08 SPEAKER Welcome to this lab on using Azure's OpenAI to process medical information. We'll start by running the first cell right here. Now, what this is going to do is that it's going to install the OpenAI library. So it downloads version 1 .66 .3 of the OpenAI package, and it's going to give us the tools that are necessary to communicate with Azure's AI service. Now, the dash queue flag allows the installation output to be a little bit less verbose and it keeps our workspace cleaner. Now, let's go over here to our next cell. Now, what this is going to do is that it's going to import all of the necessary libraries. So it's the Azure OpenAI client from OpenAI package, and also an imports package for Google Colab. It's going to allow us to access all of our API keys. So these imports make our tools available for us within our workspace. Now, moving forward, we can run the cell that retrieves our API key. Now, this command actually fetches the secret key that we have stored in Colab secret tab under Azure API key. So it uses this approach to keep all of our sensitive credentials secure instead of actually hard coding them directly in our notebook. All you will do is just create this environment variable and then paste in your API key. So let's go ahead and run this cell. | |
| 83.76 274.22 SPEAKER Now, we can scroll down a little bit more and see that in the next cell, we actually set up our connection to Azure OpenAI. So what we are doing is creating a client object that's going to handle all of our communication with Azure servers. We are providing three critical pieces of information. The specific Azure endpoint URL that's going to host our AI service, our API key for authentication, and the API version that we want to use. Now, this establishes a secure connection to Microsoft's AI infrastructure. Now, let's execute this and we can see that in the following short cell, it simply defines which AI model we want to work with. Now, in this case, we are selecting GPT for O, which is Microsoft's most advanced multimodal AI model. So this command essentially is going to tell Azure with specific AI that we want to activate when we send our request. Now, we can see here that we have set up a system message. So this is where we define the AI's role and also provide detailed instructions. We are telling the AI to act as an assistant for hospital administrations who need to extract specific information from doctors' notes. We are explicitly defining what data to look for, like age, gender, diagnosis, weight, smoking status, and specifying that we want the output formatted as a JSON. So these instructions essentially program the AI's behavior for our specific task. So let's execute this cell, and if you go to the next one, we are basically defining our test case. So it's a sample medical note about a diabetic patient, and the text represents what a doctor might write after examining a patient. So it contains various details about a patient's condition, their symptoms, and also some treatment plan. Now, the information that we want is embedded within this narrative text. It's not neatly organized. So here what we're going to do is it's going to send our first API request, and that's where the real work actually happens. We are using the chat completions API to send both our instructions, which is the system message, and our test case, which is the user input to the AI model. So the model is going to read both, it's going to understand what we're asking, it processes the medical notes, it identifies the relevant information, and then it generates a response. Now, all of this happens in just a few seconds on Azure servers. Now, in this cell right here, we can actually print the AI's response. So let's execute this, and we can see here that it's in a nice, neat, structured JSON output. It contains exactly all of the information that we asked for. So we have the patient's age, the gender, we have the diagnosis, the weight, and whether or not they were a smoker. So basically, the AI has successfully extracted the specific information from the narrative text. Now, let's move to an alternative approach. So this cell, it does essentially the same thing as our previous request, but it uses the developer role instead of the system role. Now, this is a more explicit way to provide instructions to the AI, and it's becoming more like the preferred method for developers. Now, the distinction is quite subtle, but it's important for more complex applications. | |
| 276.08 311.92 SPEAKER So we'll execute this, and we can see what the response, which is basically going to be very similar to the first result, despite the different approach. Now, we can move to a slightly more complex example. Now, this cell right here defines a much longer and a much more detailed medical note about a female patient with IVS symptoms. Now, this note, it includes various sections like Chief Complaint. There is a history of present illness section, there's a past medical history, a medications, and a social history section. Wow, | |
| 315.20 316.02 SPEAKER can't believe that happened. | |
| 321.90 452.20 SPEAKER Now, let's try a more complex example. Now, this cell defines a much longer and a much more detailed medical note about a female patient with IVS symptoms. Now, this note includes various sections like Chief Complaint, history of present illness, a past medical history, medications, and social history. It's much more representative of real -world medical documentation. So, let's run this, and then we can run the next cell to actually send this complex note to the AI. Now, we are using the same instructions as before, but testing whether the AI can handle this detail and differently structured input. So, if we execute the print cell over here, we can actually see the results. Notice how the AI still successfully extracts the key information. It correctly identifies the patient's age, the gender, and other requested details. So, this really helps to demonstrate the AI's ability to understand natural language in different formats and also in different contexts. And then finally, let's also take a look at the newer responses API. So, we'll first run this cell over here. That's going to help redefine our system message and also the user inputs using the same text as our first example. Now, this ensures that we can directly compare the results. So, here we'll also run our cell that recreates our client connection. Now, it might seem a little bit redundant over here, but it's sometimes necessary to refresh our connections when we are switching between the different API types. Now, let's execute the cell that uses the responses API. Now, instead of the messages format that's used by the chat completions API, this approach is actually going to use instructions and input parameters. So, that's what we see over here. So, this creates a cleaner separation between the AI's role definition and also the content that it's analyzing. Now, the responses API is designed for more advanced applications and also represents the future directions of AI interaction. So, we can run this and then we can run the final cell over here and that's going to help print the output from the responses API. | |
| 453.84 457.18 SPEAKER Now, you should see that it basically is going to be able to produce | |
| 458.82 501.78 SPEAKER the almost exactly the same result as our previous approaches. It's going to successfully extract the patient's information in the structured format that we would have requested. And what you've essentially witnessed is a powerful demonstration of how AI can actually transform unstructured narrative text into structured machine readable data. Now, this capability has enormous potential in healthcare for automating administrative tasks. It can help in improving data accuracy and also enabling large scale analysis of patient information. Now, the same approach can be applied across countless other industries where all of this valuable information is locked away in text documents, email, chains, reports, and other unstructured formats. | |