YouTube Tutorial: Watch the detailed walkthrough of this code and its functionalities.
This repository contains the Python code used in my YouTube tutorial for building a personal AI math tutor using the OpenAI Assistant API. The tutorial walks you through the steps to create, run, and interact with an AI assistant capable of solving math problems.
Before diving into the code, make sure you have the following prerequisites installed:
- Python 3.6 or higher
openai
Python packagepython-dotenv
package for environment variable management
- Clone this repository.
- Install the required packages:
pip install openai python-dotenv
- Create a
.env
file in your project root. - Add your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
The script is divided into functions representing each step of setting up and using the OpenAI Assistant:
create_assistant()
: Sets up a new assistant with specific instructions and tools.create_thread()
: Initializes an empty thread for the assistant.create_message()
: Sends a message to the thread.run_assistant()
: Runs the assistant to process the message.retrieve_run()
: Retrieves the result of the assistant's processing.get_messages()
: Lists all messages in a thread.
To execute a function, simply uncomment it in the script and run:
python main.py
- OpenAI API Documentation: For more in-depth understanding and additional features.
Your feedback is valuable! If you have suggestions or modifications, feel free to create an issue or a pull request. For specific queries related to the tutorial, drop a comment on the YouTube video.