Available in both English and Spanish, with slides and code
We just wrapped up our first Python + AI series, a six-part series showing how to use generative AI models from Python, with versions in both English and Spanish. We covered multiple kinds of models, like LLMs, embedding models, and multimodal models. We introduced popular approaches like RAG, function calling, and structured outputs. Finally, we discussed AI risk mitigation layers and showed how to evaluate AI quality and safety.
To make it easy for everyone to follow along, we made sure all of our code examples work with GitHub Models, a service which provides free models for every GitHub account holder for experimentation and education.
Even if you missed the live series, you can still go through all the material from the links below! If you're an instructor yourself, feel free to use the slides and code examples in your own classes.
English series
Python + AI: Large Language Models
In this first session, we introduce Large Language Models (LLMs), the models that power ChatGPT and GitHub Copilot. We use Python to interact with LLMs using popular packages like the OpenAI SDK and Langchain. We experiment with prompt engineering and few-shot examples to improve our outputs. Finally, we show how to build a full stack app powered by LLMs, and explain the importance of concurrency and streaming for user-facing AI apps.
Python + AI: Vector embeddings
In our second session of the Python + AI series, we dive into a different kind of model: the vector embedding model. A vector embedding is a way to encode a text or image as an array of floating point numbers. Vector embeddings make it possible to perform similarity search on many kinds of content. In this session, we explore different vector embedding models, like the OpenAI text-embedding-3 series, with both visualizations and Python code. We also compare distance metrics, and use both quantization and truncation dimension to reduce vector size.
Python + AI: Retrieval Augmented Generation
In our third Python + AI session, we explore one of the most popular techniques used with LLMs: Retrieval Augmented Generation. RAG is an approach that sends context to the LLM so that it can provide well-grounded answers for a particular domain. The RAG approach can be used with many kinds of data sources like CSVs, webpages, documents, databases. In this session, we walk through RAG flows in Python, starting with a simple flow and culminating in a full-stack RAG application based on Azure AI Search.
Python + AI: Vision models
Our fourth stream in the Python + AI series is all about vision models! Vision models are LLMs that can accept both text and images, like GPT 4o and GPT 4o-mini. You can use those models for image captioning, data extraction, question-answering, classification, and more. In this session, we use Python to send images to vision models, build a basic chat app with image upload, search with multimodal embedding models, and even use vision models inside a RAG application.
- Slides for session
- Code repository with examples: openai-chat-vision-quickstart
- Code repository with examples: vector-embeddings-demos
Python + AI: Function calling & structured outputs
In our fifth stream of the Python + AI series, we explore the two main ways to get LLMs to output structured responses that adhere to a schema: function calling and structured outputs. We start with function calling, which is the most well supported way to get structured responses, and discuss its drawbacks. Then we focus on the new structured outputs mode available in OpenAI models, which can be used with Pydantic models and even used in combination with function calling. Our examples demonstrate the many ways you can use structured responses, like entity extraction, classification, and agentic workflows.
- Slides for session
- Code repository with examples: python-openai-demos
- Code repository with examples: azure-openai-entity-extraction
Python + AI: Quality & Safety
In our final session of the Python + AI series, we tackle a crucial topic: how to use AI safely, and how to evaluate the quality of AI outputs. There are multiple risk mitigation layers when working with LLMs: the model itself, a safety system on top, the prompting and context, and the application user experience. Our focus is on Azure tools that make it easier to put safe AI systems into production. We show how to configure the Azure AI Content Safety system when working with Azure AI models, and how to handle those errors in Python code. Then we use the Azure AI Evaluation SDK to evaluate the safety and quality of the output from our LLM.
Spanish series
Python + IA: Modelos de Lenguaje Grande
En esta primera sesi贸n, hablamos sobre los Modelos de Lenguaje Grande (LLMs), los modelos que impulsan ChatGPT y GitHub Copilot. Usamos Python para interactuar con LLMs utilizando paquetes populares como el SDK de OpenAI y Langchain. Experimentamos con ingenier铆a de prompts y ejemplos de few-shot para mejorar nuestros resultados. Mostramos c贸mo construir una aplicaci贸n full stack impulsada por LLMs, y explicamos la importancia de la concurrencia y el streaming para aplicaciones de IA orientadas al usuario.
Python + IA: Vector embeddings
En nuestra segunda sesi贸n de la serie Python + IA, profundizamos en un tipo diferente de modelo: vector embeddings. Un vector embedding es una forma de codificar texto o im谩genes como un array de n煤meros decimales. Los vector embeddings hacen posible realizar b煤squedas por similitud en varios tipos de contenido. En esta sesi贸n, exploramos diferentes modelos de embeddings, como la serie text-embedding-3 de OpenAI, usando tanto visualizaciones como c贸digo Python. Tambi茅n comparamos m茅tricas de distancia y usamos cuantizaci贸n para reducir el tama帽o de los vectores.
Python + IA: Recuperaci贸n-Aumentada Generaci贸n
En nuestra tercera sesi贸n de Python + IA, exploramos una de las t茅cnicas m谩s populares usadas con LLMs: la Generaci贸n Aumentada por Recuperaci贸n (RAG). RAG es una tecnica que env铆a contexto al LLM para que pueda proporcionar respuestas bien fundamentadas para un dominio espec铆fico. RAG puede usarse con varios tipos de fuentes de datos como CSVs, p谩ginas web, documentos y bases de datos. En esta sesi贸n, revisamos flujos RAG en Python, comenzando con un flujo simple y culminando en una aplicaci贸n full-stack RAG basada en Azure AI Search.
Python + IA: Modelos de Visi贸n
隆Nuestra cuarta sesi贸n de la serie Python + IA trata sobre modelos de vision! Los modelos de visi贸n como GPT 4o y 4o-mini son LLMs que pueden aceptar tanto texto como im谩genes. Puedes usar estos modelos para generar descripciones de im谩genes, extraer datos, responder preguntas, clasificar, y mucho m谩s. Usamos Python para enviar im谩genes a modelos de visi贸n, construir una aplicaci贸n b谩sica de chat con im谩genes, e incluso usarlos dentro de una aplicaci贸n RAG.
- Diapositivas de esta sesi贸n
- Repositorio de c贸digo con ejemplos: openai-chat-vision-quickstart
- Repositorio de c贸digo con ejemplos: vector-embeddings-demos
Python + IA: Llamadas a funciones y salidas estructuradas
En nuestra quinta sesi贸n de la serie Python + IA, exploramos las dos formas principales de hacer que los LLMs generen respuestas estructuradas seg煤n un esquema: llamadas a funciones y salidas estructuradas. Comenzamos con las llamadas a funciones, que es la forma m谩s utilizada para obtener respuestas estructuradas, y hablamos de sus limitaciones. Luego nos enfocamos en el nuevo modo de salidas estructuradas disponible en los modelos de OpenAI, que puede usarse con modelos Pydantic e incluso combinarse con llamadas a funciones. Nuestros ejemplos demuestran las m煤ltiples formas en que puedes usar respuestas estructuradas, como extracci贸n de entidades, clasificaci贸n y flujos de trabajo con agentes.
- Diapositivas de esta sesi贸n
- Repositorio de c贸digo con ejemplos: python-openai-demos
- Repositorio de c贸digo con ejemplos: azure-openai-entity-extraction
Python + IA: Calidad y seguridad
En nuestra sesi贸n final de la serie Python + IA, discutimos un tema crucial: c贸mo usar la IA de manera segura y c贸mo evaluar la calidad de las salidas de IA. Hay m煤ltiples capas de mitigaci贸n cuando se trabaja con LLMs: el modelo en s铆, un sistema de seguridad superpuesto, el prompt y contexto, y la experiencia de usuario de la aplicaci贸n. Nuestro enfoque es en las herramientas de Azure que facilitan poner sistemas de IA seguros en producci贸n. Mostramos c贸mo configurar el sistema Azure AI Content Safety cuando se trabaja con modelos de Azure AI, y c贸mo manejar esos errores en c贸digo Python. Luego usamos el SDK de Evaluaci贸n de Azure AI para evaluar la seguridad y calidad de la salida de nuestro LLM.