Will AI replace us all?
The recent launch of OpenAI’s chatbot, ChatGPT, has stirred up a lot of excitement and hype in the artificial intelligence (AI) world. ChatGPT is a groundbreaking development in AI technology — it is the first ever AI-based chatbot that can interact with humans in natural language. It is able to respond to questions and generate meaningful conversations with no prior training.
This development is a major milestone in the world of AI and has sparked a lot of discussion about its impact on our daily lives. Many people are wondering:
Will AI replace us all
Which I reckon, is a common reaction when new technological developments are made, it’s natural to worry about the implications of that technology. But the truth is, AI won’t replace us all. AI is just a tool that can be used to speed up and automate certain tasks. And while it may be able to do some things better than humans, it won’t be able to replace us completely.
From what I’ve been doing, AI is like my personal assistant. It can do the tedious tasks that you don’t like doing, and spend time on them. As someone who loves to write, AI has been a great help in refining my grammar, fixing mistakes, and inserting stronger words to emphasize my ideas, even though English isn’t my first language.
AI is your friend, not an enemy
As a Software Engineer, I find it super exciting with the recent developments in AI. For sure I had my bag of worry, but ever since I tried tinkering with it, my worries have been put to rest. AI is here to stay and it is here to help us. It is a superpower that will make us more productive and efficient.
We should treat AI as our engineers and ourselves as the tech lead of this small team of two. Meaning? we should provide guidance and context to the AI just like tech leads provide guidance and context to their engineers. Take a look at this command asking AI to generate a backend application.
Generating a backend — Part 1
Help me create a golang backend with two endpoints, GET accounts to retrieve all accounts from database, and POST accounts to insert an account into the database.
// Import the necessary packages
import (
"database/sql"
"net/http"
)
// Create the database connection
db, err := sql.Open("driverName", "connectionString")
if err != nil {
log.Fatal(err)
}
// Handler for GET accounts
func getAccounts(w http.ResponseWriter, r *http.Request) {
// Prepare the query
stmt, err := db.Prepare("SELECT * FROM accounts")
if err != nil {
log.Fatal(err)
}
// Execute the query
rows, err := stmt.Query()
if err != nil {
log.Fatal(err)
}
// Iterate through the rows
for rows.Next() {
// Get the values from the row
var accountID int
var accountName string
var accountBalance float64
err = rows.Scan(&accountID, &accountName, &accountBalance)
if err != nil {
log.Fatal(err)
}
// Write the account details to the response
w.Write([]byte(fmt.Sprintf("Account ID: %d\nAccount Name: %s\nAccount Balance: %f\n\n", accountID, accountName, accountBalance)))
}
}
// Handler for POST accounts
func postAccounts(w http.ResponseWriter, r *http.Request) {
// Get the account details from the request
accountID := r.FormValue("accountID")
accountName := r.FormValue("accountName")
accountBalance := r.FormValue("accountBalance")
// Prepare the query
stmt, err := db.Prepare("INSERT INTO accounts (accountID, accountName, accountBalance) VALUES (?, ?, ?)")
if err != nil {
log.Fatal(err)
}
// Execute the query
_, err = stmt.Exec(accountID, accountName, accountBalance)
if err != nil {
log.Fatal(err)
}
// Write a success message to the response
w.Write([]byte("Account successfully added!"))
}
// Create the HTTP server
http.HandleFunc("/accounts", getAccounts)
http.HandleFunc("/accounts", postAccounts)
log.Fatal(http.ListenAndServe(":8080", nil))
This piece of code above is AI-generated. What do you think? It doesn’t work, isn’t it?
Now try giving more context.
Generating a backend — Part 2
Help me create a golang backend with two endpoints, GET accounts to retrieve all accounts from a postgres database, and POST accounts to insert an account into the postgres database. Accounts table has id as the primary key, name as a non-null string, and created_at field to record when the row is created. the GET accounts endpoint should return an array of string of names, and the POST endpoint takes a name as a parameter.
package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
_ "github.com/lib/pq"
)
// Account contains id, name and created_at fields
type Account struct {
ID int `json:"id"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
}
func main() {
// Connect to Postgres database
db, err := sql.Open("postgres", "postgresql://user:password@localhost:5432/database_name?sslmode=disable")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Create HTTP server
http.HandleFunc("/accounts", func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
getAccounts(w, db)
case http.MethodPost:
postAccount(w, r, db)
default:
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprint(w, "method not allowed")
}
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
// getAccounts retrieves all accounts from Postgres
func getAccounts(w http.ResponseWriter, db *sql.DB) {
rows, err := db.Query("SELECT id, name, created_at FROM accounts")
if err != nil {
log.Fatal(err)
}
defer rows.Close()
accounts := []Account{}
for rows.Next() {
var account Account
if err := rows.Scan(&account.ID, &account.Name, &account.CreatedAt); err != nil {
log.Fatal(err)
}
accounts = append(accounts, account)
}
// Return accounts as array of strings
accountNames := []string{}
for _, account := range accounts {
accountNames = append(accountNames, account.Name)
}
jsonAccounts, err := json.Marshal(accountNames)
if err != nil {
log.Fatal(err)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, string(jsonAccounts))
}
// postAccount inserts an account into Postgres
func postAccount(w http.ResponseWriter, r *http.Request, db *sql.DB) {
// Parse name from request body
var name string
if err := json.NewDecoder(r.Body).Decode(&name); err != nil {
log.Fatal(err)
}
// Insert account into database
stmt, err := db.Prepare("INSERT INTO accounts (name, created_at) VALUES ($1, $2)")
if err != nil {
log.Fatal(err)
}
if _, err := stmt.Exec(name, time.Now().UTC()); err != nil {
log.Fatal(err)
}
defer stmt.Close()
// Return success
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "success")
}
And now the code runs, and it even imported the correct driver library for Postgres which is github.com/lib/pq
. And all we needed to do is just adding more context. But of course, the code is a bit messy, but it’s a huge improvement compared to our first generation. Maybe try defining the framework we’re gonna use (e.g. echo, gin, etc.), or say that log.Fatal
is not a good practice if we’re using it in an HTTP handler, and so on.
Conclusion
Is it right to panic about AI taking over your job? No.
Is it right to do nothing differently? Also no.
We should embrace the new technology and adapt, and make use of AI and other new technologies to improve our work and efficiency. Instead of worrying about it taking away our jobs, learn to use it to improve our work and stay competitive in the job market.
Make it help you create better placeholder content to present to your client, make it help you write better documentation, make it help you deal with repetitive customer complaints, etc. The possibility is endless.
Either be afraid, complain, and reject. Or make a good use of it.
Like how I asked AI to create this article.