All You Dev's Are Toast - ChatGPT knows Motoko

I just talked to the ChatGPT bot and asked it:

write me code in motoko for a canister that will display “hello world” when i visit the canister’s URL on the internet computer, and provide instruction for how to upload the code and create the necessary canister. tell me any thing else I should know in order to accomplish this task.

The Answer:

To create a canister in Motoko that displays “Hello, World!” when its URL is visited on the Internet Computer, you can use the following code:

Copy code

use std

const greetings: String = "Hello, World!"

pub const main(args: List[String]): void {
  std.debug.log(greetings)
}

This code defines a String variable called greetings with the value “Hello, World!” and a main function that uses the std.debug.log method to print the value of the greetings variable to the console. When the canister’s URL is visited, this function will be executed and the message “Hello, World!” will be displayed.

To upload this code and create the necessary canister, you can follow these steps:

  1. Install the Internet Computer command-line tools and create an account on the network if you have not already done so.
  2. Compile the Motoko code to a WebAssembly binary using the dnet command-line tool.
  3. Create a new canister using the dnet command-line tool and specify the WebAssembly binary from the previous step as the canister’s code.
  4. Publish the canister using the dnet command-line tool.
  5. Visit the canister’s URL on the Internet Computer to see the “Hello, World!” message.

Here is an example of how these steps might be performed using the dnet command-line tool:

Copy code

# Compile the Motoko code to a WebAssembly binary
dnet compile -o hello.wasm hello.mo

# Create a new canister with the specified WebAssembly binary
dnet create -n hello -c hello.wasm

# Publish the canister
dnet publish -n hello

# Visit the canister's URL on the Internet Computer to see the "Hello, World!" message

Note: These instructions are just an example and may vary depending on your specific setup and configuration. Consult the documentation for the dnet command-line tool for more detailed instructions.

1 Like

Not valid Motoko code :slightly_smiling_face:

2 Likes

Also, not sure what dnet is but I’m pretty sure using it won’t result in a deployed canister :slightly_smiling_face:

I tried this exact input and this was the response I got:

I’m sorry, but I am not familiar with “motoko” as a programming language or the internet computer. It is possible that “motoko” is a programming language and the internet computer is a specific platform or framework, but I am not able to browse the web to verify this information. In order to write code for a canister that will display “Hello World”, you will need to use a programming language and platform that are supported by the internet computer.

To create a canister that will display “Hello World” when you visit its URL, you will need to follow these general steps:

  1. Write the code in the programming language of your choice. The specific code you will need to write will depend on the programming language and platform you are using.
  2. Upload the code to the internet computer, either by creating a new canister or by adding the code to an existing canister.
  3. Test the canister by visiting its URL in a web browser to ensure that it displays the “Hello World” message as expected.

Note: The steps and code required to create a canister that displays “Hello World” may vary depending on the specific platform and programming language you are using. You may need to consult the documentation for your platform and programming language for detailed instructions.

It does know about the Internet Computer insofar as someone at a distance might “know of” ICP (try asking it for a simple explanation of Solana versus ICP for instance) but definitely not about Motoko.

Though as far as automating a lot of tasks (such as “dfx devops” you might need), all someone would have to do it is feed it an example set, and it would make a great way tool for new developers to get over the initial learning curve.

I tried this the other day and was relieved that my job is still relevant.
Nonsense code, yet very confident that its accurate.

oh i failed to mention i had to give it simpler questions/instructions like “write me hello world in motoko” and work my way to the longer text.

well guess this AI bot isn’t all it’s cracked up to be, you guys have some time :slight_smile:

Copilot writes 30% of my Motoko.

2 Likes

Where this ChatGPT gonna be in the next 5 years ?

cool thanks i’ll check it out

so i’ve got this from the bot this time:

write me the code for printing “hello, world!” in motoko

Here is an example of how you can print “Hello, World!” in Motoko:

Copy code

import std::io;

fn main() {
    io::print("Hello, World!");
}

This code will print “Hello, World!” to the console when it is run. The import statement brings in the io module, which contains functions for performing input and output operations in Motoko. The main function is the entry point of every Motoko program, and it is called when the program is run. The io::print function is used to print a string to the console.

I hope this helps! Let me know if you have any questions.

!(data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e)

what does the following motoko code result in? “import Debug “mo:base/Debug” actor HelloWorld { public func main() { Debug.print(“Hello World!”) } }”

The Motoko code you provided is an actor that defines a HelloWorld actor with a single function, main. The main function will be executed when the actor is started, and it will print “Hello World!” to the console using the Debug.print function.

The import statement at the beginning of the code brings in the Debug module from the mo:base/Debug package. The Debug module contains functions for performing debugging operations, such as printing messages to the console.

I hope this helps! Let me know if you have any other questions.

!(data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%2730%27%20height=%2730%27/%3e)

do you think that is a better way to code “hello world” in motoko then your example?

The Motoko code you provided is an actor that defines a HelloWorld actor with a single function, main, which will be executed when the actor is started. This is a different way to write a “Hello, World!” program in Motoko compared to the example I provided earlier, which used a main function and the io::print function to print “Hello, World!” to the console.

Both approaches are valid ways to write a “Hello, World!” program in Motoko, and which one is “better” will depend on your specific needs and preferences.

The first example I provided is a simple program that uses the io module to print a message to the console. It is a good choice for a beginner’s program or for a small program that does not need to perform any complex operations.

The second example you provided uses an actor and the Debug module to print a message to the console. Actors are a powerful tool in Motoko for building concurrent and distributed systems, and they can be useful for more complex programs that need to perform a large number of operations or communicate with other actors.

I hope this helps! Let me know if you have any other questions.

I think you’re using chatGPT to generate these forum posts, too :sweat_smile:

1 Like

i’m attempting to feed the bot some code and hoping it will learn while it is in session lol

The best way to do this would be install the command line tool available from them, then you’d have to form the input as JSON using prompt and response key value pairs. Note you can use VSCode with their AI copilot and as many have noted, it’ll generate a lot of Motoko code for you (although this not the openai engine afaik).

1 Like

The future is bright. Feels like we are on track to fulfill Idiocracy (2006) - IMDb and WALL·E (2008) - IMDb

2 Likes

chatgpt don’t know any motoko when i try, the training data didn’t have motoko code in it. maybe wait until gpt4 might got better chance.
here is solidity version of coding

Just to note, ChatGPT was trained on data up to late 2021, so it might not have the latest Motoko code in its training data, if it even has enough to begin with.

1 Like