Current AI is Phenomenal

It really is.

I’ve been completely blown away by the progress that AI has made recently.

Firstly, like most people, I became obsessed with AI Painting programs like DallE and Stable Diffusion. I even decided to become the world’s most unlikely fashion brand, by using AI painting to express a certain fetishism for synthesizers, DJ decks and other toys combined with anachronistic geeky humour.

So you too can wear Gargoyle DJs on a gothic cathedral.

https://i.etsystatic.com/38454376/r/il/48feb1/4393582573/il_1588xN.4393582573_pocw.jpg

And medieval nuns discussing a Moog.

White Unisex Crewneck T-shirt with Medieval Nuns image 4

And carry a Victorian DJ tote bag

Tote Bag : Victorian DJ image 1

And admire pictures of pieces of fantasy gear like this:

Make Noise Da Vinci Buchla Acrylic Print 30x40 cm / 12x16″ - Horizontal

But even while I was marvelling at the images that AI was producing, I was still sceptical that AI would make much of a dent in programming.

I wasn’t wowed by CoPilot.

But now ChatGPT has, indeed, blown me away. Not sure if it’s just because it has a better UX. Or if it’s really just cleverer than CoPilot.

But it is able to do things like this: I asked it for some file-uploader code in Clojure / ClojureScript (I really need to add an image gallery to Cardigan Bay). Here’s the response:

Sure, here is an example of how you could allow users to upload pictures to a gallery in your app using Ring and ClojureScript:

On the server side, using Ring, you could create a route that accepts file uploads and stores them in a directory on the server. Here is an example:


(defn upload-route
  "Handler for uploading files to the server. Accepts a file parameter
   and saves the file to the specified directory."
  [request]
  (let [upload-dir "./uploads"
        file (:file request)]
    (if (not (empty? file))
      (do
        (spit (str upload-dir file) (:content file))
        {:status 200
         :headers {"Content-Type" "text/plain"}
         :body "File uploaded successfully"})
      {:status 400
       :headers {"Content-Type" "text/plain"}
       :body "Error uploading file, no file specified."})))

On the client side, using ClojureScript, you could create a form that allows the user to select a file to upload, and then submits the file to the server using an AJAX request. Here is an example:

(ns my-app.core
  (:require [goog.net.XhrIo :as xhr]
            [goog.events :as events]
            [goog.dom :as dom]))

(defn upload-file
  "Handler for uploading a file to the server. Accepts a file input element
   and sends the selected file to the specified URL using an AJAX POST request."
  [file-input url]
  (let [file (.-files file-input)
        form-data (js/FormData.)]
    (if (not (empty? file))
      (do
        (.append form-data "file" (aget file 0))
        (xhr/send url
                  (fn [event]
                    (let [xhr (.-target event)]
                      (if (= (.-status xhr) 200)
                        (dom/setTextContent
                          (dom/getElement "upload-status")
                          "File uploaded successfully")
                        (dom/setTextContent
                          (dom/getElement "upload-status")
                          "Error uploading file"))))
                  "POST"
                  form-data
                  {"Content-Type" "multipart/form-data"}))
      (dom/setTextContent
        (dom/getElement "upload-status")
        "Error uploading file, no file selected."))))

(let [file-input (dom/getElement "file-input")
      upload-form (dom/getElement "upload-form")]
  (events/listen upload-form
                 events/EventType.SUBMIT
                 (fn [event]
                   (events/preventDefault event)
                   (upload-file file-input "/upload"))))

Note that this is just an example and may not include all the necessary code to fully implement file uploads in your app. You may need to add additional error handling, security checks, and other features to make it work for your specific use case.

OK. So I haven’t tried this yet. Maybe it’s riddled with bugs. But eyeballing it, it looks like a pretty good first draft. I mean, it’s as good as I’d get by googling an example and copying and pasting some code from it. And it took 30 seconds to generate, rather than maybe half an hour concentrated googling. (Which would probably be a couple of hours in terms of finding a window to do it, getting into the zone and concentrating etc.)

So … what do I think now? I’m gonna try this. And if it works … really I’m changing my mind drastically. I thin AI is really going to internalize enough about the structure, syntax, inner coherences of code, that AI based tools are about to completely transform and revolutionise coding.

Which is scary. But also very exciting given how much frustration there still is in software development.

Leave a comment