Eight months ago Altman wanted an AI CEO. Now he says nobody does.
Back to Tutorials
aiTutorialintermediate

Eight months ago Altman wanted an AI CEO. Now he says nobody does.

July 28, 202615 views5 min read

Learn to build a practical AI assistant that can manage tasks and respond to natural language commands using OpenAI's API and Flask.

Introduction

In this tutorial, we'll explore how to build a simple AI assistant that can help manage tasks and reminders, similar to what Sam Altman envisioned for AI leadership roles. While we won't create a full AI CEO, we'll build a practical AI assistant that can understand natural language commands, store tasks, and provide responses using OpenAI's API. This project will teach you how to integrate AI capabilities into practical applications and understand the current state of AI assistant development.

Prerequisites

Step-by-step Instructions

1. Set up your development environment

We need to create a project directory and install the required dependencies. This step ensures we have all the necessary tools to build our AI assistant.

mkdir ai-assistant
 cd ai-assistant
 pip install openai flask python-dotenv

2. Create environment configuration

Store your OpenAI API key securely in a .env file. This prevents exposing your key in your code and follows security best practices.

echo 'OPENAI_API_KEY=your_actual_api_key_here' > .env

3. Initialize the main application

Create the main Python file that will handle the AI assistant logic. This file will load environment variables, set up the OpenAI client, and define the core functionality.

import os
from openai import OpenAI
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Initialize OpenAI client
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))

class AIAssistant:
    def __init__(self):
        self.tasks = []
        self.conversation_history = []

    def add_task(self, task):
        self.tasks.append(task)
        return f"Added task: {task}"

    def get_tasks(self):
        return self.tasks

    def process_command(self, command):
        # Add command to conversation history
        self.conversation_history.append({"role": "user", "content": command})
        
        # Create a prompt that includes context about tasks
        prompt = f"""
You are an AI assistant helping manage tasks. Current tasks: {self.tasks}

User command: {command}

Respond in a helpful, concise way. If the command mentions adding a task, add it to the list. If it asks for current tasks, list them. If it's a general question, answer appropriately.
"""
        
        try:
            response = client.chat.completions.create(
                model="gpt-3.5-turbo",
                messages=[
                    {"role": "system", "content": "You are a helpful assistant that manages tasks."},
                    {"role": "user", "content": prompt}
                ]
            )
            
            # Add AI response to conversation history
            ai_response = response.choices[0].message.content
            self.conversation_history.append({"role": "assistant", "content": ai_response})
            
            return ai_response
        except Exception as e:
            return f"Error processing command: {str(e)}"

# Create an instance of our assistant
assistant = AIAssistant()

4. Create a simple web interface

Build a basic web interface using Flask to interact with our AI assistant. This allows us to test the assistant through a browser interface rather than just command-line input.

from flask import Flask, render_template, request, jsonify

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/chat', methods=['POST'])
def chat():
    user_input = request.json['message']
    response = assistant.process_command(user_input)
    return jsonify({'response': response})

@app.route('/tasks', methods=['GET'])
def get_tasks():
    return jsonify({'tasks': assistant.get_tasks()})

@app.route('/add_task', methods=['POST'])
def add_task():
    task = request.json['task']
    response = assistant.add_task(task)
    return jsonify({'response': response})

if __name__ == '__main__':
    app.run(debug=True)

5. Create HTML template

Create a basic HTML interface for testing our assistant. This provides a user-friendly way to interact with our AI system.

<!DOCTYPE html>
<html>
<head>
    <title>AI Assistant</title>
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        #chat-container { max-width: 600px; margin: 0 auto; }
        #messages { border: 1px solid #ccc; height: 300px; overflow-y: scroll; padding: 10px; margin-bottom: 10px; }
        #input-box { display: flex; }
        #input-box input { flex: 1; padding: 10px; }
        #input-box button { padding: 10px 20px; }
    </style>
</head>
<body>
    <div id="chat-container">
        <h1>AI Assistant</h1>
        <div id="messages"></div>
        <div id="input-box">
            <input type="text" id="user-input" placeholder="Type your command...">
            <button onclick="sendMessage()">Send</button>
        </div>
    </div>

    <script>
        function sendMessage() {
            const input = document.getElementById('user-input');
            const message = input.value;
            
            if (message.trim() === '') return;
            
            // Display user message
            addMessage('You', message);
            input.value = '';
            
            // Send to backend
            fetch('/chat', {
                method: 'POST',
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify({message: message})
            })
            .then(response => response.json())
            .then(data => {
                addMessage('AI', data.response);
            });
        }
        
        function addMessage(sender, message) {
            const messages = document.getElementById('messages');
            messages.innerHTML += `<div><strong>${sender}:</strong> ${message}</div>`;
            messages.scrollTop = messages.scrollHeight;
        }
        
        // Allow Enter key to send message
        document.getElementById('user-input').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                sendMessage();
            }
        });
    </script>
</body>
</html>

6. Run the application

Start your Flask application to test the AI assistant. This step actually launches the web server that will respond to your commands.

python app.py

Then open your browser to http://localhost:5000 to interact with your AI assistant.

7. Test the assistant

Try these commands to test your assistant:

  • "Add a task to review the project documentation"
  • "What are my tasks?"
  • "Schedule a meeting with the team for tomorrow"
  • "How can I improve my productivity?"

Summary

This tutorial demonstrated how to build a practical AI assistant that can manage tasks and respond to natural language commands. While we didn't create a full AI CEO, we built a foundation for AI-powered task management that shows the current capabilities and limitations of AI systems. As Sam Altman's comments suggest, we're still in the early stages of AI leadership roles, but tools like this show how AI can enhance human productivity rather than replace human judgment. The assistant we built can understand context, maintain conversation history, and respond appropriately to various commands, demonstrating the practical applications of AI in everyday work environments.

Source: TNW Neural

Related Articles