Outils pour utilisateurs

Outils du site


issue192:mon_opinion2

Ceci est une ancienne révision du document !


ChatGPT (https://chat.openai.com/chat) is an artificial intelligence (AI) tool that, amongst other things, can create text based on a request from an end user. So, I thought I would use it to write an article for this magazine by entering “Write an article for Full Circle Magazine on Script Programming with Artificial Intelligence”. Had I gone ahead with this, you could now be reading the result.

However, while ChatGPT is perfectly capable of producing reasonably intelligent text from such a command, this article hasn’t actually been generated by AI. But, as we will see, some of the article’s content has indeed been produced using ChatGPT. In particular, we will explore how this tool can be of assistance in script programming for LibreOffice Basic.

But, first let me explain the scenario. I have a LibreOffice document (ODT file) that contains the lists of topics that my computer club has covered over the past three years in our weekly, on-line, question-and-answer sessions. Each week I build an agenda for the upcoming session as a simple text file (TXT) that lists the titles of the topics to be discussed next. This text file is used for a variety of purposes, one of which has been to manually add the list of new topics to the main ODT index file. I want to automate this latter process by developing a macro that will read the topics from the text file and add them to the end of the ODT file.

I don’t know all that much about object-oriented programming so, when I want to create a macro for a document in LibreOffice Writer, my practice is to use Google to search for code extracts that I can then modify and string together to produce the final product. And, this is precisely what I did to build the required macro in this case.

But, then I saw a YouTube video of an individual using ChatGPT to create computer code in a number of programming languages by simply telling the AI bot what was required. Now, perhaps LibreOffice Basic is a bit of a backwater item in terms of mainstream programming, but I figured that it would be worth a shot to see if I could use ChatGPT to develop the code for my macro.

Now, I know how to read and write lines of text from an ASCII file. My problem is that the ODT file isn’t a simple text file. The ODT format is a special type of ZIP file that contains a number of XML and other components. So, the trick is to have the macro open the ODT file, identify the component that contains the body text of the document, add the desired lines at the end, and close the file.

At present, use of ChatGPT is free. All that is required is to create an account on the system, or login using an established Google account. Once logged in, one enters a request as a string into a text box. My request was “Write a program in LibreOffice Basic to add a string to the end of an odt file”.

The result was amazing – as shown by the following (partial) screenshot:

ChatGPT effectively produces a custom tutorial on building the macro. Each required step in the process is explained and the relevant code extract displayed. Finally, all the code that has been developed for the requested macro is shown as a complete block:

In essence, this code segment is very close to the macro code that I had produced over some considerable time, having had to research several web postings to identify the required techniques. Clearly, it is very generic code, and only covers part of what is required for the final macro. But, it is evident from this simple test that the AI bot is fully capable of generating “modules” of code that can readily be adapted for the desired purpose, and that such modules could be quickly consolidated into a fully-functional macro.

The other consideration is that the current version of ChatGPT is at an early stage in the development of AI tools. As such applications become more sophisticated, and the computer systems running them become more powerful, it is highly likely that their use in computer programming will become ubiquitous. In the interim, ChatGPT is a useful tool for anyone seriously developing programs, macros and scripts, and a really interesting option for those who just wish to see what AI can do.

issue192/mon_opinion2.1682786965.txt.gz · Dernière modification : 2023/04/29 18:49 de auntiee