This workshop is designed to introduce you to the capabilities of OpenAI's APIs, including the Responses, Embedding, and File Search APIs, with hands-on demonstrations and code examples.
Slides for this workshop are available here.
- Python 3.x
- OpenAI Python Library (installation guide below)
- OpenAI API Key
- Internet Connection
Before we dive into the demos, please ensure your environment is set up with the necessary software and libraries:
# Install the OpenAI library and other dependencies
pip3 install -r requirements.txtThis demo illustrates how to utilize the Responses API to create an interactive chatbot.
- Developer Message: Sets the context for the AI (e.g., "You are a friendly and supportive teaching assistant for CS50. You are also a cat.")
- User Interaction: Accepts user input to simulate a conversation.
- API Integration: Utilizes the
responses.createmethod to generate responses based on the conversation history. - Streaming Responses: Demonstrates how to handle streaming responses with
ResponseTextDeltaEvent.
This demo showcases the use of OpenAI's text embeddings to perform semantic search, enabling the identification of the most relevant information chunk in response to a user query. This technique can significantly enhance the way educational content is queried and retrieved, making it a powerful tool for educators and students alike.
- Text Embeddings: Illustrates how to generate and utilize text embeddings using OpenAI's
embeddings.createmethod. - Semantic Search: Demonstrates how to compute similarity scores between embeddings to find the most relevant content.
- Integration with Responses API: Combines the result of semantic search with the Responses API to generate contextually relevant responses.
- Pre-computed Embeddings: Before running this demo, ensure you have an
embeddings.jsonlfile containing pre-computed embeddings for various content chunks relevant to your subject matter. - Custom Model Selection: You can experiment with different models for embeddings to suit your content and accuracy requirements.
This demo showcases how to use the Responses API with the file_search tool and a vector store to provide tailored responses based on specific data files. It is particularly useful for building retrieval-augmented generation (RAG) applications for events, courses, or research projects.
- File Search Tool: Guides you through uploading files, creating a vector store, and using the
file_searchtool to answer CS50 or computer science-related questions. - Data File Utilization: Demonstrates how to upload and associate data files with a vector store to enrich the model's responses.
- Streaming: Shows how to stream responses incrementally using
ResponseTextDeltaEvent.
- Data Preparation: Before running the demo, ensure your
FILES_DIRpoints to the directory containing relevant files you wish to search over. We have pre-configured the use of lecture transcripts in the example. - Customization: You can customize the instructions, behavior, and tools to fit various educational or research contexts.
This demo showcases how to build a local retrieval-augmented generation (RAG) pipeline using ChromaDB as a persistent vector store. Instead of uploading files to OpenAI, it processes SRT subtitle files into time-based chunks, embeds them locally with OpenAI's embedding model, and stores them in a ChromaDB collection for fast semantic search.
- SRT Chunking: Parses subtitle files and merges consecutive captions into ~30-second chunks, preserving start and end timestamps.
- Local Vector Store: Uses ChromaDB with persistent storage so embeddings are computed once and reused across sessions.
- OpenAI Embeddings: Embeds chunks using the
text-embedding-3-largemodel via ChromaDB'sOpenAIEmbeddingFunction. - Streaming: Streams responses incrementally using
ResponseTextDeltaEvent. - Source References: Each response includes clickable YouTube links that jump to the exact lecture timestamp.
- Ingestion: Before chatting, run
ingest.pyto process all SRT files and populate the ChromaDB collection. This only needs to be done once (or re-run if the data changes). - Chat: Run
chat.pyto start the interactive Q&A. Use the-vor--verboseflag to display the retrieved chunks. - Customization: You can adjust chunking parameters (
CHUNK_MIN_DURATION,CHUNK_MAX_DURATION), the embedding model, and the number of retrieved chunks inconfig.py.
# Step 1: Ingest SRT files into ChromaDB (one-time)
cd examples/rag/chromadb
python3 ingest.py
# Step 2: Start the interactive chat
python3 chat.py
# Or with verbose mode to see retrieved chunks
python3 chat.py -v