
Artificial Intelligence (AI) can seem intimidating, but getting started is easier than you might think. In this short guide, you’ll go from installing Python to calling an AI model from your code in under 30 minutes.
Install Python
If you don’t already have Python:
- Windows/Mac:
Go to https://www.python.org/downloads/ and download the latest Python 3.x version.
Check installation:
python --version
Install a Code Editor
You can write Python in any text editor, but VS Code is beginner-friendly.
Download from https://code.visualstudio.com/.
Create a Project Folder
Open your terminal (Command Prompt, PowerShell, or Mac Terminal) and create a new folder:
mkdir my_first_ai
cd my_first_ai
Install Required AI Libraries
For our example, we’ll use the OpenAI API to interact with an AI model like GPT.
pip install openai
Get an API Key
- Sign up at https://platform.openai.com/.
- After logging in, create an API Key and keep it safe (you’ll need it in your code).
Write Your First AI Code
Create a file called ai_test.py
and paste:
from openai import OpenAI
# Initialize client with your API key
client = OpenAI(api_key="YOUR_API_KEY_HERE")
# Send a request to the AI model
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Write a 2-line poem about AI."}
]
)
# Print the AI's response
print(response.choices[0].message["content"])
Run the Code
In your terminal:
python ai_test.py
You should see something like:
AI thinks and dreams in endless streams,
Coding the future in digital beams.
Play Around
- Change the user message to ask the AI different questions.
- Try
"Write a short Python code to reverse a string"
or"Explain quantum computing in simple words"
.