Playing with AI and Learning to Keep It Simple, Silly

Playing with AI and Learning to Keep It Simple, Silly

Yesterday I was playing with AI in the evening and I asked it to help me write a function that would detect whether an array item was a photo or a video. I told the AI, this is a photo array item, and this is a video array item. I want the photo array item to display the img src code and for the video item to be displayed with video src code. At first it failed to detect anything and gave me an error message. I decided to highlight the photo array item snippet and the video array snippet. 


It didn’t come back with an error but it did not display any img or video code. In the end I decided to say “here’s the img src tag. I want you to detect whether the file is mp4 or jpg. If it’s mp4 add the video player, and if it’s a photo load the image. I went from asking it to read the array to determine what to do, to “check the filetype and load the appropriate src type. That worked, and required very little code. 


Don’t Over-Engineer With AI


The moral I came away with, after the trial and error I went through last night is that whilst AI is great at reading and understanding code, and giving us answers it can sometimes fail. I was making something far more complicated than it had to be and chatGPT got confused, as would a human trying to complicate something simple. 


PHP has a lot of functionality built into it. It has tools that allow it to read exif information, file types and more, and if you know about these tools, then you can come up with elegant solutions, rather than complicated ones. 


The Winning prompt: 


I want to check whether a file is .jpg or .mp4. I want the default to be this: echo ‘ ' . $title . ' ‘; It the loop detects that the file is .mp4 I would like the video player to be loaded instead.


The Code


if (isset($article['media'][0]['uri'])) {

$fileUri = $article['media'][0]['uri'];

$fileExtension = pathinfo($fileUri, PATHINFO_EXTENSION);

if ($fileExtension === 'mp4') {

    echo '';

} else {

    echo '' . $title . '';

}

}


It gives a summary of what it did: 


In this code, we use the pathinfo() function to extract the file extension from the $fileUri. If the file extension is .mp4, we generate the video tag with the src attribute pointing to the video file, and if it’s not .mp4, we generate the img tag with the src attribute pointing to the image file.


But Wait, There’s More


I then asked chatGPT “Would it be better to determine a file type by reading the array type from a php array, or checking the file directly with php info?


The answer it gave was “In this code, we use mime_content_type() function to retrieve the MIME type of the file. We then check if the MIME type starts with image/ or video/ to determine if it’s an image or a video. This approach provides a more reliable way to determine the file type based on its content.” after providing an alternative code for me to use instead.  


Iterating


I was reading an article about AI and how Stack Overflow didn’t want to use AI for answers because it provided them with a lot more work but I think that AI is interesting because it allows you to experiment with different approaches. In fact you can ask chatGPT a simple question. Is Solution A or Solution B if I want to do C12, and it will come back with an answer, and then you can ask about how to write the code. In my eyes the strength of chatGPT is that it allows you to experiment and cycle through options much faster than if you were reading dozens of articles and solutions to find one that would work. the more I play/experiment, the more I learn, and the more I learn, the faster I can engineer prompts that will get the code I require. I like consolidating what I have learned, with chatGPT as a pair programmer. 

My AI Teacher

My AI Teacher

Today I want to discuss something different. I want to discuss using AI as a teacher, rather than as a tool to replace us. For a few days I have been playing with the Instagram json file that I got when I requested my archive. With this json file I thought about things to do, and in so doing asked chatGPT for help, and it provided answers.


Adapting the Questions


When you ask chatGPT to do something it will do what you asked. If you see that you got a partial answer then you can tell chatGPT more specifically what to do. In some cases I would ask it to do something, but I didn’t tell it that the data was in an external file, so I told it the name of the external file and it was added.


You Still Need to Think And Understand


Although ChatGPT is a great tool you need to learn to debug. Sometimes if you get an error message you can ask chatGPT how to resolve it, but in other cases, chatGPT will not realise what the error is.


The Zero Width Asset


A heatmap of photos taken per day from the Instagram JSON data for my account


Yesterday I was trying to generate a heat map of when I took photographs with ChatGPT via the instagram json file but it did not detect that the height for an element had been set to zero. It’s by experimenting that I found this error and fixed it. ChatGPT gave me a useful answer, but only resolved part of what I was trying to achieve. I had to do the rest.


Testing and Double Checking


In one case I told chatGPT that I wanted to make something available in the head element. It helped me to do that but then removed some functionality from another part of the page. I had to tell it “put that functionality back”, not in those words, and it did. Double check everything.


Trial And Error


Coding, and finding solutions, with chatGPT is about having an idea, and seeing if, and how, to get chatGPT to understand the request that you’re making. I find that I often have to ask a question several times, and in different ways, before I get to an answer that is useful for me. The more you play with chatGPT the more you learn about its quirks and how to avoid them.


Context Aware


One feature that I find especially useful with chatGPT is that it is context aware. With Google you can ask how to do something, but usually you can’t go into the specifics because it is not as context aware. The best example I can think of is the array. With an array you have layers within layers and it can be confusing to see whether something is one or three layers down, and how precisely to get to that data. With chatGPT you can say “here’s one array item, I want to retrieve x from that array, how do I do it, and it does. It gives you the request you need to access that bit of information from the array.


Practical Example


The Instagram Archive JSON is thousands of elements, but they all have the same structure, as long as they have the same data. The first step is to create the foreach loop to cycle through the data. Getting the first bit of info, with the instagram json file was easy, but deciphering the exif element wasn’t, so I asked chatGPT for help within this specific context, and it worked fine. I could then copy and paste for the exif that I had not asked it to help me with.


Converting Time Stamps from Epoch to Human Readable Dates and Times


There are plenty of places where you can find where to convert from epoch to machine readable time. chatGPT can also provide you with a context relevant solution, rather than a generic one.


Learning by Repetition


People may say “but you’re not learning, you’re just playing with chatGPT in the hope that it will give the right answer, to which I answer that we all learn in different ways. People that studied computer science and understand all of the theory might be able to read the fabulous manual, and understand everything, but for those of us that are learning bits and pieces, in an informal context, chatGPT allows us to ask “how do I do this in that context?”


We are learning three skills in processes such as mine. The first is to think about how to write functions for an app. The second is being able to communicate this desire to an AI. The skill has a name: Prompt engineering. It wouldn’t have a name if it wasn’t an important aspect of working with AI. The final skill we are learning is how to assemble code to make it work as we want it to work.


ChatGPT doesn’t just give us a few lines of code. It provides us with relevant contextual information to help us understand what is happening.


In short chatGPT can be used as a tutor, or course program, to teach us how to write better code, when others may not be around, or have the time to help us.


Udemy Courses


At least two of the “teachers I followed on Udemy, to learn about JavaScript and other technology have now made courses teaching people how to use AI to help them with their workflows. Rather than watch how others are using chatGPT I am playing and learning, with projects I think up. It’s fun. I should call it experimenting, rather than playing, but in the end I am playing.


Does this make sense to chatGPT?


Does that make sense to chatGPT?


Would chatGPT understand what I mean if I asked this?


ChatGPT and Debugging


I find it really interesting that chatGPT can be used for debugging. It tells you, do this using that library, assuming that the library is installed, but if it isn’t then you need to install it, but that’s not the end. You need to see which version chatGPT meant for you to implement. I got error messages and asked chatGPT for help, tried one version, got another error message. I then shared the new error message and chatGPT said “Oh, if you’re using this version then you’re meant to use this code, rather than that code.” I didn’t change the code. I swapped versions and the app worked.


Conclusion


The more time you invest in prompt engineering, with a specific goal in mind, the more you will learn, and the more you learn, the more useful chatGPT becomes. It goes from being an interesting curiousity to being an interesting tool.

From Instagram Archive to PHP Website

From Instagram Archive to PHP Website

Three years ago I stopped using Instagram because I was tired of seeing influencers and adverts rather than by the people I chose to follow. The cherry on the cake, that pushed me to dump Instagram is when they changed the location of the Post button from the left corner to the top right and changed the default from photo to story.


For ten years or more I used instagram and shared photos, and I enjoyed capturing at least an image or two every single day. It’s because Instagram was bought by Facebook that I fell out of love with the site and decided not to use it anymore. The community had been lost, so what good was there in sticking around? 


Instagram to WordPress


In 2020 I played around for two days and I developed a work flow to take my posts json file, and convert it to CSV before importing it to wordpress via a plugin. It worked well, but I never used it. 


The Laravel Concept


For a short time I was thinking of trying to get Laravel to drive the Instagram clone but soon changed my mind, due to the amount of learning it would required. I settled on a simpler, yet practical solution. The PHP Array. I had used PHP arrays for one or two sections of my page, as well as individual pages. It’s simple and intuitive to use, with few complications to debug. 


JSON to PHP array


Recently I saw discussions about how pixelfed made it possible to import the instagram json file to pixelfed and that’s what encouraged me to play with the Instagram json file. This time I tried a different tact. 


The first step was to download the most recent json file and save it locally. Once this was done I converted the json file 


I asked chatGPT for help. I asked it how to convert from json to php array. The answer summarised is “$json = json_encode($array);”


I then asked how I would generate a file:


$json = json_encode($array);

$file = ‘data.json’;

file_put_contents($file, $json);


After this It was a matter of trial and error to read the php array data. My idea was to create a loop that would cycle through each post individually and display the image, as well as the related data. Usually I would achieve this by trial and error, as I have done, in the past, with other projects. 


chatGPT Helps to Access Array Data


By myself I was able to retrieve the URI and display it. I struggled with the timestamp and exif data so I asked chatGPT to help me. It gave me examples of how to get the URI, the iso info, and the title. The arrays contain more info but I extrapolated that from the example chatGPT had provided me with. 


At this point the page was ready to experiment with displaying the content. At first it was just text. I then added the required html to display the image properly and to size it correctly. When that was working properly it was time to add pagination. 


In the past I would have spent time Googling for examples of pagination and selecting one that worked well but this time I asked chatGPT for help. 


It helped me with pagination, except that the pagination was from page one to one thousand six hundred or more. That’s excellent, if you want that, but I didn’t. I wanted the pagination to be paginated, so I asked chat GPT to help with this too. It did. I then noticed that I needed back and forth, so I asked chatGPT for help yet again. 


EXIF volatility


When the site was loading individual images and the relevant information I flicked through the images and noticed that some did not have exif data so I asked chatGPT to write an if else loop that would display exif info if it was available, and ignore it if it wasn’t. This worked well. 


Time Taken


chatGPT is a fantastic tool, when you know what you want, and you understand how to get it to work, but you’re not 100 percent on the code aspect. I had the basic functionality of the json to PHP site functional within an hour to an hour and a half. I then spent hours tidying things up, adding a little functionality here and there. With chatGPT if you know what you want to do but you’re not certain of how to do it, then it shines. 


During this process I asked a question, it gave an answer, when I saw the answer I tweaked my question, until the result was what I wanted. 


Adding CSS


When I was happy with how the site was behaving I changed from displaying three images, to five and then I added styling. For styling you can copy and paste from old projects, or various sources, or you can ask chatGPT to give you a black background with white text and white borders and it will provide you with the code. Within seconds your theme is ready. 


And Finally


I am comfortable with PHP. I have been redesigning my website to run off of PHP rather than html or a CMS and it works well. chatGPT didn’t provide me with the concept or direction. I did that. I thought of the steps and workflow, and got chatGPT to provide me with reminders of how to do things. It’s because I knew what I wanted to do, that I achieved my goal within a short amount of time. This is really a post about how I used prompt engineering to get chatGPT to help me achieve the goal I wanted to reach, within minutes, rather than hours, or days. 


i went from having a big, clunky wordpress blog, to a few lines of php, to do the same thing. I can add functionality with time. For now it shows my instagram photos efficiently.


The Result

Prompt Engineering and chatGPT

Prompt Engineering and chatGPT

If you follow chatGPT and AI courses you will often come across the term “Prompt Engineering”. Prompt Engineering is the art and science of writing instructions so that AI understands what you would like to do. With time and practice you can be as specific as you like. You can fine tune your request until you get precisely what you are looking for. 


The Limit of chatGPT. 


“As an AI language model, my responses are generated based on a mixture of licensed data, data created by human trainers, and publicly available data. These sources may contain publicly available information up until my knowledge cutoff in September 2021. It’s important to note that I do not have direct knowledge of specific data gathering practices or the individual sources used to train me.”

chatGPT


The limit of chatGPT is that it goes up to September 2021. This means that code solutions for specific apps, like a css style sheet for calckey.social won’t work. You need to ask questions about CSS and adapt the resulting code to work with Calckey or other newer code. 


Writing Tic Tac Toe and Hangman


Last night I asked chatGPT to write Tic Tac Toe, Hangman and a ToDo app in C++, php and java. The results were variably successful but this shows the power of chatGPT. In theory you could browse to github or other website and just cut and paste the code. The result is similar, but with one key difference. 


With chatGPT you can ask “create a simple nav bar that changes colour on mouse over using UL and LI tags and it will generate that code for you. 


“please create a simple nav menu using html ul and li elements and style it with css so that text is highlighted on mouseover”.


html and css code for a nav bar
html and css code for a nav bar


The point is that chatGPT can write entire apps, if you engineer the right prompt, but it can also generate snippets of code for you with a specific result in mind, as in the example above. 


Show something in a table


When you ask chatGPT for a table of things to do in barefoot shoes
When you ask chatGPT for a table of things to do in barefoot shoes


Show something in an HTML table


When you ask chatGPT for a table of things to do in barefoot shoes in html
When you ask chatGPT for a table of things to do in barefoot shoes in html


As you see chatGPT understands the instruction, provides me with a result which I can then tweak to match my desired outcome. Instead of spending ten to fifteen minutes writing and formatting the table with this data, I can get chatGPT to do it for me. 


In What is Generative AI Pinar Seyhan Demirdag said of AI that “AI does the work and humans focuses on the vision, the idea and the purpose.” In other words AI is an assistant. The more you study prompt engineeering, and the better you get at getting the desired outcome, the more useful and valuable AI, and your skills in using AI become. 


And Finally, For Now


AI behaves like a person. The more clearly and concisely your instructions are, the more the output will reflect your desired outcome. AI is constantly learning from Big Data. Our task is to learn how to give instuctions, prompt engineering, as it’s called within the industry, so that AI provides the results we require, saving both time, and to some degree, learning. I have just scraped the surface. I want to learn more. 

chatGPT, GPT3 and Reading Time

chatGPT, GPT3 and Reading Time

Time for a new discussion to take place. Reading time. Do you read through articles or do you skim them. Is reading the headline enough or do you read every word of the article? I ask because in the age of chatGPT and GPT3 I would ask the same question as I asked about social media.


If you want to discuss ROI for businesses and PR firms or advertisers then you need to discuss ROI for users too. Facebook, Instagram and Twitter wanted to control the timeline by using a “home” feed. The Home feed is an algorithm driven feed that shows you popular content, rather than content by friends, that you and they would converse about. The result is a lonely social media experience. The ROI goes down, That’s why I took a break from Twitter to play with Mastodon and revive my blogging habit.


Now we’re coming to the new discussion, about chatGPT. From the tests I have run with chatGPT it is a glorified encyclopaedia rather than AI. It spits out predetermined answers, rather than showing signs of learning and logic. I played with Copperman years ago, and other projects. With those, the more you chatted with the app, the more intelligent it would become. With chatGPT it always gives standard responses. It’s boring. It has no humanity. It has no character.


Writing is a creative process. You sit there, knowing that you want to create content but you need to spend time thinking of ideas, and then you need to write to the word count that you, or others has set. That process injects humanity into what you write. It also means that someone has taken the time to develop an idea, and maybe even proofread it.


By making it easy to generate content for WordPress and other platforms chatGPT, GPT-3 and other technologies are making it harder to find content worth reading. One of the biggest challenges when looking for content., reviews and information about products is the spam. the boiler plate content that people generate for a Casio watch, or other products.


Content should be written by humans for humans. The more noise we generate by fake AI, the more difficult it will be to find human content, by humans, for humans. That fake AI will also create formulaic answers to specific questions, rather than original content.


I love technology when it replaces the need for humans to do boring and repetitive tasks that can be automated, but something creative, such as writing we should keep humans. One tech mag recently allowed AI to write articles and those articles then had to be proofread and corrected by human editors.


ChatGPT is Hype


Recently I was reading a book about AI and deep learning and it wrote about how there is a cyclical habit of people to say “this is a great step forward in AI” only for interest to flare up, and then die down again as the miracle solution is understood and interest wanes again. chatGPT might seem exciting to some, but to me this looks like a human language search engine, rather than proper AI. Give it random words and it doesn’t do anything. I asked chatGPT “how fast does a squirrel run and it crashed, twice. It isn’t intelligent.