In this article I share my experience generating a Rust program  and a Telegram BOT with ChatGPT.

I ended my 2022 the way it should be: coding and learning.

In this last year week I decided to try ChatGPT’s much-vaunted AI  to learn how to program some of the resolutions I set for 2023, for example: Rust and a BOT for Telegram.

What is ChatGPT?

AI” is an acronym  for Artificial Intelligence  .

ChatGPT is an Artificial Intelligence developed by OpenAI that has caused a stir since November 30, 2022 for the maturity of its ML (Machine Learning) models: GPT-3, which performs a variety of natural language tasks, Codex, which translates natural language into programming code, and DALL· E, which creates and edits original images.

OpenAI’s goal is to develop and promote safe and “friendly” AI. American entrepreneur Sam Altman (former president of startup accelerator Y Combinator) co-founded OpenAI in 2015 with Elon Musk, who left the project in 2020. Sam Altman serves as CEO of the San Francisco-based company.

ChatGPT is not the first, nor the only, nor the most advanced AI. Its merit lies in putting it in the hands of the general public free of charge, albeit limited, as an opener of the revolution that is coming upon us.

Generating a Rust Language Program with ChatGPT

When trying to make an API in Rust for handling a table of users in a MongoDB database, the result was a bit frustrating.

I built almost the entire API with ChatGPT. The result was good for encouraging me to learn Rust, but the program generated from the query to ChatGPT didn’t work.

I asked him for a complete program that implements CRUD (Create, Read, Update and Delete) operations on a table of users in MongoDB from Rust, with each operation in a separate function and the main function all in a single .rs file

I had to do this little by little so that I could put all the parts together.

Then I asked to implement an API in Rust that handles a user table in MongoDB with Endpoints for all CRUD operations and that follows the REST style, and that can be called by Ajax in Javascript.

He did it for an old version of the MongoDb dependency for Rust, he didn’t give me the configuration of the Cargo.toml file  (especially the necessary features for the serde), he didn’t include the ‘uses‘ of all the necessary elements (for example, for ‘tokyo‘), he didn’t include the structs for the Form and Query in the ‘warps‘ that define Endpoints, among many other things.

I spent hours trying to fix it so that it was an MVP (minimum viable product) and in the end I got stuck at the end of the Endpoint to query a document in the MongoDb database.

I understood something important: for a highly typed programming language, which could be the substitute for C Language, it is not advisable to try to learn in the Learning-by-Example style, in my case it is necessary to take some course, and then put it into Rust.

Generation of a Telegram BOT in Python Language with ChatGPT

Here I did get a very satisfactory result for two reasons: I already knew how to program in Python and a few years ago I tried to do this work in PHP (more or less in 2018, based on this repo by Eleirbag89 and this article by Stackoverflow on how to get price from bitcoin to USD with PHP api) and somehow I already knew how to start the development of the BOT,  although some minor things changed over time.

According to Wikipedia, a BOT is a computer program that automatically performs repetitive tasks over the Internet through a chain of commands or previous autonomous functions to assign an established role; and that has the ability to interact, changing state to respond to a stimulus.

Initially, the project had the objective of giving the quotes of Bitcoin and then having a mechanism to warn when the cryptocurrency reached a specific minimum value, sending an alert through the same Telegram.

What I liked about this exercise was that a project dormant for 4 years, to which I had invested many hours of work to finally put it aside (and I even lost the source code due to several moves from one country to another, changing computers and not putting it in a Github repository) to be able to develop it from scratch in 21 hours (2 days of work practically).

The end result can be summed up in these elements:

Github repository:

hatps://github.com/tomkat-cr/market_alert_from

Telegram BOT URL:

https://t.me/ocr_marketalert_bot

And the Telegram BOT looks like this:

A screenshot of a computer

Description automatically generated

ChatGPT Conversation Tips

Little by little I’ve become friends with this AI…

The conversation was in Spanish entirely and ChatGPT speaks it very well.

Initially, I asked him for an overview of the development.

Since the free version of ChatGPT has limitations on the size of the responses, I gradually ask it for the rest of the things that are cut.

When you are asked for code in a specific programming language, at the end or at some point you should also be asked for configuration files, installation procedures, among other things, to avoid – for example – dependency version conflicts.

The other thing is that I initially asked him to give me the procedure to put the BOT to work in Vercel’s free service, and so far I have not been able to get it to work. I gave up and had to put a question on StackOverflow to see if anyone would help me fix a problem with port forwarding between the BOT in Python and the Vercel Serverless instance.

In the end it was a good experience (there is no bad thing that does not come with good), because I learned the two working modes of the Telegram BOTs, the Polling and the WebHook, I learned how to deploy applications in Fly.io, and most importantly: feeling blocked, minimized, defeated by not being able to deploy in Vercel, in a matter of hours I looked for a viable solution with something new,  even if that means investing time in learning and learning and learning more! The same thing happened to me when Heroku ended its free tier and I had to move the backend from FynApp to Vercel and frontend to Github Pages.

CONCLUSION

It was a very interesting and enriching experience. Definitely, the initial creative development process is streamlined and he challenged me to finish it in record time.

However, I’m still not going to lose my job by being replaced by an AI.

This is missing quite a bit. In the meantime, let’s learn how to develop Artificial Intelligence and Machine Learning.

Here are two interesting articles:

  1. How to program Artificial Intelligence? [5 languages]
  2. 12 Steps to Applied Artificial Intelligence

The best of all was the corrections my mom made minutes before the 2022 new year eve when I shown her this Post. It was something beautiful and unexpected, in addition to her being hired to do the review of all the Posts for my Personal Branding project.