Pre-requisites
- A computer
- Open AI API Key
- Python 3+ installed
- Pip3 (usually included with Python install)
- Git
- Clone this repository
- (Optional, for Lesson 2 samples) Install Ollama to run Llama and some other models locally: https://ollama.com/
- In Terminal: ollama pull llama3.2
- For vision capabilities: ollama pull llama3.2-vision
Recommended
- Visual Studio Code IDE
Clone the repo
- Create a folder somewhere on your computer, e.g. ai-tutorial-py
- Open the Terminal app (or console on Windows) and use the cd command to navigate to the folder you created
- git clone https://github.com/bowdoincollege/ai-tutorial-py.git
Managing dependencies in Python
Make sure you are in the ai-tutorial-py directory in the Terminal app.
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -r requirements.txt
- Copy the .env.example file to .env and fill out the environment variables
Making the very basic 'hello world' call to the OpenAI API.
Accepting basic user input.
Adding context so that the chat bot remembers the conversation.
Taking advantage of Markdown syntax to improve the output formatting
Taking things up a notch. Adding code to scrape the web and generating a summary of text that exceeds the context window of the LLM (128,000 tokens for OpenAI models). This is often referred to as RAG: Retrieval-Augmented Generation, supplementing data from an external source from the LLM training data.
lesson-1-5b.py (Supreme Court docs)
Getting started with OpenAI vision capabilities.
Creating a dynamic web application
This sample code shows you how to run an llm locally with Ollama, e.g. llama 3.2, etc. These take up a lot of hard drive space and can be slower than using the commercial APIs, but it's free!
- Python Rich Console library: https://realpython.com/python-rich-package/
- OpenAI quickstart: https://platform.openai.com/docs/quickstart?language-preference=python&quickstart-example=completions
- LangChain summarization: https://python.langchain.com/docs/tutorials/summarization/#map-reduce
- Ollama quickstart: https://github.com/ollama/ollama/blob/main/README.md#quickstart
- LangChain Python Ollama: https://python.langchain.com/docs/integrations/llms/ollama/
- OpenAI Python library: https://github.com/openai/openai-python