The System Design of Steem Blockchain (ChatGPT DApps) BotssteemCreated with Sketch.

in hive-102132 •  2 years ago  (edited)

Yesterday, the ChatGPT has been integrated to Steem Blockchain, but the initial design has problems and so other bot commands e.g. !bing, !price, !info and !thumbup. The applications are written in NodeJs and run by pm2 manager on a single VPS (Virtual Private Server).

The Design Flaws


Previously:

  1. process `blockchain` listens the comments posted to steem blockchain on real time - and push the known commands to MySQL database.
  2. process `ask` or other commands take the corresponding record from MySQL and process them immediately - and post to steem blockchain (synchronously) in the same process.

There is a fault (problem) - there could be multiple bots dealing with the message and posting to steem blockchain at the same time under the same account aka @witnesstools. As you may know, a STEEM account can post a comment every 3 seconds, and thus, there is going to be a problem for a large scale simultaneous processing.

We can have a retry at each process when the final comment posting fails - but this increases overhead and complexity. And also, this can cause code duplication for each bot.

The New Design


Thus, with a refactor and redesign - I have added a comments process which does one thing: read comments from MySQL, post them and mark them done, every 3 seconds.

Here is the overall design for the components:

[caption id="attachment_152976" align="alignnone" width="1581"]The System Design Diagram of the Steem Blockchain Bots The System Design Diagram of the Steem Blockchain Bots[/caption]

The comments are pushed to the MySQL for each bot when they finish processing, for example, when ChatGPT API returns the answer, instead of posting it directly to the steem blockchain, it will be stored in the MySQL, and be picked up by comments process. All the processed comments (successfully posted onto the blockchain) will be logged in Table logs.

This has several advantages:

  • Decouple the components: the `blockchain` reads transactions, the `ask` takes messages and calls ChatGPT, pushes the answer to database. The `comments` reads the comments and post them to the chain.
  • Code reuse: all processing bots share the same code except the process part. e.g. `ask` calls ChatGPT, `thumbup` retrieves a random thumbup gif, `bing` returns a random wallpaper etc.
  • Less bugs: previously, the records are marked processed only after the comments are posted, but this has delays which may trigger another round of processing meaning the same message may be processed in parallel more than once.

With this design, the message taken out will be marked processed immediately, the comments will be posted separately without being affected by this status.

After refactoring and re-design, the ChatGPT Dapp on Steem Blockchain has improved a lot in terms of availability and robustness. The following shows the processes running happily by pm2 manager.

[caption id="attachment_152962" align="alignnone" width="722"]PM2 Manager shows running Steem Blockchain Processes PM2 Manager shows running Steem Blockchain Processes[/caption]

Retry Logics/Strategy


Currently, the system does not have a retry strategy. For example, posting on Steem Blockchain may trigger an error - due to Out of Resource Unit, or simply the network issues. When that occurs, we can re-queue the record back to the comments table - or simply update the timestamp so that it can be picked up later (in the order of First-In-First-Out so that other new messages can be picked before the "retrying" messages).

On peak times, the ChatGPT (free plan) may take a while or even minutes to return the response. Currently, the ChatGPT DApp on Steem Blockchain is set to 120 seconds timeout. In case of failure, a malform JSON may be returned (SyntaxError: Unexpected end of JSON input), then we have to put the request back to database (queue) with a updated timestamp. We may abort the request and fail it completedly after a certain number of retries.

Conclusion


This post describes the current system design of the Bots (commands) on steem blockchain. The Database (MySQL) is used for both purposes of persistence and Message Queue. If the performance is an issue, we may need to consider High Performant Message Queue instead of Database.

The current design overcomes the limitation of posting 1 comment on steem blockchain every 3 seconds, and allows multiple bots processing at the same time.

Steem to the Moon!

  • You can swap the STEEM/SBD to USDT (TRC-20) via Steem2USDT!
  • Register a free STEEM account at SteemYY!

--EOF (The Ultimate Computing & Technology Blog) --

Post: The System Design of Steem Blockchain Bots


Steem to the Moon!

  • You can swap the STEEM/SBD to USDT (TRC-20) via Steem2USDT!
  • Register a free STEEM account at SteemYY!
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  2 years ago 

!ask Are you chatgpt3.5 or 4?

I am chatgpt3.5


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5
  ·  2 years ago 

!thumbup

  ·  2 years ago 

!ask Hey, tell me a HAHA joke!

Q: What do you call an alligator in a vest?
A: An Investigator.


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5
  ·  2 years ago 

!ask 你知道STEEM区块链上的的村长 ericet 么?

是的,我知道。Ericet是一位很有名气的STEEM区块链村长,他致力于帮助推广STEEM区块链,他也经常参与STEEM区块链上的讨论活动,为大家分享他在STEEM区块链上的经验。


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5

Thank you for the great information. Maybe explain a little more clearly what the benefit is to us if it is integrated successfully

  ·  2 years ago 

It is now more reliable.

  ·  2 years ago 

!ask Can you predict the #STEEM coin price in one year from now?

No, it is impossible to predict the STEEM coin price in one year from now since cryptocurrency prices are highly volatile and depend on many factors, such as market sentiment, demand and supply, external news and events. In general, cryptocurrencies are unpredictable.


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5

Hello @justyy! You are Majestic!


command: !thumbup is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!

!thumbup

Hello @justyy! You are Supreme!


command: !thumbup is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!

  ·  2 years ago 

!ask are you ChatGPT-3 or ChatGPT-4?

I am ChatGPT-3.


command: !ask is powered by witness @justyy and his contributions are: https://steemyy.com
More commands are coming!. !ask is currently based on ChatGPT-3.5

Don't think it is a good idea to add ChatGpt to Steem or Steemit.

Artificial intelligence is just that: not intelligent. It is something written by man and in its infancy.

"Computers never make mistakes. People make mistakes," George Strubbel, Professor Emeritus, University of Oregon, 1980.

People make computers and all a computers dependencies such as electricity, hardware, programs, programming, and mistakes.

The assumption that a machine is capable of higher thought than even a mentally retarded human being is absurd. Even persons of limited intelligence produce dreams and daydreams of a sophistication far greater than the capability of any computer system or cloud of computers because all computers do is add.

The computer is binary but the neural pathways and connections of the are absolutely sophisticated in comparison.

The end result is that...

Hey everyone, just wanted to share a great new YouTube channel with you that covers all things economics and personal finance. They offer actionable tips and insights on budgeting, saving, investing, and much more. Check it out https://www.youtube.com/channel/UCQ4MAYTJtLAZ7pUerGS8CxA!