From the course: Enterprise AI Development with GitHub Models and Azure
Exploring the Jupyter Notebook examples
From the course: Enterprise AI Development with GitHub Models and Azure
Exploring the Jupyter Notebook examples
- [Instructor] The Python examples show the same way of working with GitHub models as the basic, streaming, multiturn examples. It also has the chat with image, embeddings, and the tools example. In the main read me of the Python folder, you'll find that these are examples for each of the different SDKs again, OpenAI, Azure AI, and Mistral. Running the samples is as simple as executing the file again. Everything here is self-contained. To run the streaming example, just execute the streaming file. We can see the streaming flow happen in the terminal, so let's take a look at the code. To get us started, you can see that we are importing the SDKs that we need so that we can communicate with the model. We pick a model that we use and we configure the client that handles the communication to the model's endpoint and authenticate with our own GitHub token. We call the ChatCompletions endpoint and send in a part of a conversation, including the system and user prompt. Notice the streaming equals true configuration indicating to the model that we want to receive a stream of data. And while we get data back from the call, we immediately stream the content in the choices object out into our terminal. In the folder you can see that all the other examples we have already looked at in the previous videos are there as well. The Python example adds one more way of explaining things, and that is with a Jupyter Notebook, which has the IPYNB extension. This is a common way of working in the data and machine learning community. So let's take a look. A Jupyter Notebook has the notion of a runtime engine that can execute cells of work. These cells contain steps and are annotated here with numbers. This way, you can combine the steps with textual explanation and have the code that executes the step inside of a cell. When you hover over a cell, there is a little run button on the left that indicates you can execute the single cell. You can see the time we're running there to execute it, and we get a new set of instructions for this cell on the top-right. This means you can now change the cell and rerun it if you want to. This makes it very easy to get started. I especially like the options you have with notebooks to add more coding comments and explanations. You can even include links to external documentation. In cell three, we can see that the basic setup for the Python client is configured. The GitHub token is loaded and the client itself is started. Cell four shows how to work with the embeddings model to embed the Hello World input and then return the embeddings. Cell five shows how to be more efficient with the API and use less calls by sending in more strings at the same time, as the inputs can contain an array of strings. In the next steps at the bottom, the authors even included links to the cookbooks as they have called the other Jupyter Notebooks. Very helpful linking into the same repository. If you want to dive deeper into working with Jupyter Notebooks, then I recommend this course from Josh McQuiston. The course shows you all the ins and outs to make working with notebooks a breeze.