Introduction
In this tutorial, you'll learn how to interact with OpenAI's language models using the Python programming language. This is the same technology that powers Microsoft's Copilot 365, which is mentioned in the recent TechCrunch article about GPT 5.6 being the preferred model. By the end of this tutorial, you'll be able to make your own AI-powered applications that can answer questions, generate text, and help with productivity tasks.
Prerequisites
To follow along with this tutorial, you'll need:
- A computer with internet access
- Python 3.6 or higher installed on your system
- An OpenAI API key (free to get from openai.com)
- Basic understanding of how to use a command line or terminal
Step-by-Step Instructions
Step 1: Set Up Your Development Environment
Install Python (if not already installed)
First, make sure you have Python installed. Open your terminal or command prompt and type:
python --version
If Python is installed, you'll see a version number. If not, download and install Python from python.org.
Install the OpenAI Python Library
Now, install the OpenAI Python library which will allow us to communicate with the AI models:
pip install openai
This command installs the official OpenAI library that provides easy access to their API.
Step 2: Get Your OpenAI API Key
Create an OpenAI Account
Visit https://platform.openai.com/ and create a free account. This is where you'll get your API key.
Generate Your API Key
After logging in, go to the "API Keys" section and click "Create new secret key". Copy this key - you'll need it in the next step.
Step 3: Create Your First AI Application
Create a New Python File
Create a new file called ai_app.py in your preferred code editor.
Set Up the Basic Code Structure
First, we'll import the OpenAI library and set up our API key:
import openai
# Set your API key
openai.api_key = "sk-...your-api-key-here..."
# This is where we'll call the AI model
Important: Replace "sk-...your-api-key-here..." with your actual API key. Never share your API key publicly!
Step 4: Test Your AI Connection
Create a Simple Test Function
Add this code to test that your connection works:
def test_ai_connection():
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Hello, AI!"}
],
max_tokens=50
)
print("AI Response:", response.choices[0].message.content)
return True
except Exception as e:
print("Error connecting to AI:", str(e))
return False
# Test the connection
if test_ai_connection():
print("Success! You're connected to the AI.")
This code tests if your API key works correctly by sending a simple message to the AI and getting a response back.
Step 5: Build a Productivity Assistant
Create a More Useful Function
Now, let's create a function that can help with productivity tasks like summarizing text:
def summarize_text(text):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant that summarizes text concisely."},
{"role": "user", "content": f"Please summarize the following text in 2 sentences: {text}"}
],
max_tokens=100
)
return response.choices[0].message.content
# Example usage
sample_text = "Artificial intelligence is transforming how we work and live. It helps with tasks like writing, analysis, and decision-making. Many companies are investing heavily in AI technology."
summary = summarize_text(sample_text)
print("Summary:", summary)
This function creates a productivity assistant that can summarize long texts into shorter, more manageable versions - similar to what Microsoft Copilot 365 might do for users.
Step 6: Make It Interactive
Build a Simple Chat Interface
Let's make our application interactive by allowing users to ask questions:
def chat_with_ai():
print("AI Assistant: Hello! I'm here to help you with questions. Type 'quit' to exit.")
while True:
user_input = input("\nYou: ")
if user_input.lower() in ['quit', 'exit', 'bye']:
print("AI Assistant: Goodbye!")
break
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": user_input}
],
max_tokens=150
)
ai_response = response.choices[0].message.content
print(f"AI Assistant: {ai_response}")
# Uncomment the line below to run the chat
# chat_with_ai()
This creates a chat interface where you can have a conversation with the AI, just like you might with Microsoft Copilot 365.
Step 7: Run Your Application
Execute Your Code
Save your file and run it in the terminal:
python ai_app.py
When you run the code, you should see the AI respond to your test messages. If you uncomment the chat_with_ai() line, you'll be able to have an interactive conversation with the AI.
Summary
In this tutorial, you've learned how to set up an AI application using OpenAI's technology. You created a basic connection to the AI, built functions to summarize text, and made an interactive chat interface. This is exactly the kind of technology that powers Microsoft's Copilot 365, which is mentioned in the TechCrunch article about GPT 5.6. By understanding these basics, you can start building your own AI-powered productivity tools that help with writing, analysis, and problem-solving tasks.
Remember to keep your API key secure and explore other OpenAI models available for different tasks. As AI technology continues to evolve, you'll be well-prepared to use these powerful tools in your own projects.



