You can ask to explain code, write tests, refactor for perfomance or readability etc.
Ask HN: Can ChatGPT generate fully functional code?
51–60 of 69 posts
Re: Ask HN: Can ChatGPT generate fully functional code?
#52Earlier quoted context omitted.
All you need is to prompt it with "Continue" and it will keep going exactly where it left off.
I've heard this quite a lot too, but it commonly doesn't work. I've had it respond thinking I was talking about using a `continue` statement somewhere in the code, and other times it simply just reprinted the whole code starting from the beginning. If you hit the "Try again" button enough it will usually eventually work, but it again has the problem where a lot of the time the formatting of the text gets messed up.
There has been a few times where the app hangs with the three dots jumping - but that seems to be an issue with server overload.
I've been able to make lots of mini apps in JS/HTML/CSS that with very little tweaking could be dropped into codepen fully working.
Most of these required ~3 "continue the code example" and were started with at prompt like "Show me the code for an app in js, html, css where a user can input his weight in kg, and his daily calorie deficit. Then a canvas element shows a graph of his future weight loss changing live according to the changed input."
Absolutely amazing that it works. You can even dump an error from the console if it needs tweaking and it often fixes the error from the msg on the first try.
You can also say "give me just X function" or "continue above example from the line with 'someFunction or something'" or "give me just the css again but make it more modern" and it just works.
Re: Ask HN: Can ChatGPT generate fully functional code?
#53First of all, don't use ChatGPT for that. Use full GPT-3, specifically the code models (ie. code-davinci-002). ChatGPT is a subset & tweak of the full GPT-3 model to make a good chatbot, and it's actually less capable than the full model. It's strange to me that people are going crazy over ChatGPT when GPT-3 has been out for months now. More info on the difference between ChatGPT and GPT-3: https://dev.to/ben/the-dif…
For me the conversational interface is what makes the AI useful as a coding companion, how do you integrate GPT-3 in your workflow ?
Re: Ask HN: Can ChatGPT generate fully functional code?
#54Having said that, I usually compare it with Junior programmers, more like someone just learning a new programming language. You can expect that level of performance from ChatGPT!
Re: Ask HN: Can ChatGPT generate fully functional code?
#55Seems like there would be far more content to train on and less restrictive criteria.
Re: Ask HN: Can ChatGPT generate fully functional code?
#56Earlier quoted context omitted.
You can ask for a simple example of a CRUD app, here's my code output: const express = require('express') const app = express() // define the model for a user const User = { name: '', email: '' } // create a new user app.post('/users', (req, res) => { const user = Object.assign({}, User, req.body) // save the user to a database, etc. res.send(user) }) // read a list of users app.get('/users', (req, res) => { // retri…
Well that's impressive :) But of course unless you had programming experience, you would have no way to structure this output correctly and actually take it live
Given this code for an example CRUD app, what unix commands could I run on my system to actually run this code?
$pasted_code_from_gp_comment
GPT's response:
> To run this code, you would need to install the express npm package by running npm install express in your terminal. After that, you can run the app by using the node command followed by the name of the file containing the code, for example: node app.js. This will start the server, which you can then access by going to http://localhost:3000/ in your web browser.
With follow up questions, such as "it says npm is not recognized command"; gpt will explain what that error means and how to fix it
This is the response to "it says npm is not recognized command":
> If you get an error that npm is not recognized as a command, it means that the npm command is not available on your system. This could be because you don't have Node.js installed, or because the npm command is not in your system path.
> To fix this error, you will need to install Node.js on your system. You can download and install the latest version of Node.js from the official website: https://nodejs.org/en/. After installing Node.js, you should be able to run the npm command from your terminal.
> Once you have installed Node.js, you can also check if the npm command is in your system path by running where npm on Windows or which npm on macOS or Linux. This should print the location of the npm command on your system. If it doesn't print anything, you may need to add the npm command to your system path manually.
> If you're still having trouble, you can try looking for solutions online or reaching out to the Node.js community for help. There are many forums and online communities where you can ask questions and get help from experienced users.
Re: Ask HN: Can ChatGPT generate fully functional code?
#57Earlier quoted context omitted.
Well that's impressive :) But of course unless you had programming experience, you would have no way to structure this output correctly and actually take it live
I asked GPT how I could run it with this prompt: Given this code for an example CRUD app, what unix commands could I run on my system to actually run this code? $pasted_code_from_gp_comment GPT's response: > To run this code, you would need to install the express npm package by running npm install express in your terminal. After that, you can run the app by using the node command followed by the name of the file cont…
Can’t wait to see what this technology looks like in a year.
Re: Ask HN: Can ChatGPT generate fully functional code?
#58It all depends on what you mean by generate fully functional code. In my experience, it is able to generate code snippets that are useful but very rarely can be simply copy & pasted into your work. The experience is actually quite similar to Stack Overflow.
I was wanting to try to do something I wasn't familiar w/ at all: Building a mobile app with flutter, and so far I've got the gPT chat completely cloned in flutter, I'm just missing the additional features I wanted to add like saving chats, sharing screenshots and text chats, entering a url, and scraping the page text to ask ChatGPT to summarize, or maybe write a blog post similar to this but don't copy anything, etc....
Re: Ask HN: Can ChatGPT generate fully functional code?
#59So far it's created some pretty amazing tailwindcss layouts for me, and a flutter app to interface with chatGPT that I want to add more features like saving, sharing, etc.. In 3 hours with zero flutter experience I can now at least do as much as the website does. That's pretty amazing.
Edit: YMMV -- imho you do need to be mid-senior level in tech/programming skills to know and find the best prompts to get it to go your way, there's some trial and error and your ide will usually let you know about errors/etc and you can ask them to fix it and gpt does a good job of correcting things.
Re: Ask HN: Can ChatGPT generate fully functional code?
#60 Write a small application in javascript that logs in to news.ycombinator.com with credentials passed on the command line and then posts the following message:
>Fellow members,
>
>I'm curious to know what are some of the best prompts to use on ChatGPT to understand its full-fledged capability as a newbie developer.
>
>One of the things I noticed, is that it produces the requested code in the cleanest manner but it's not complete. For instance, I tried the prompt - "give me the python code for TicTacToe Game" and the code produced was incomplete.
>
>Have you all encountered the same or my prompt is inappropriate?
Output:Here is an example of a small JavaScript application that logs in to news.ycombinator.com using credentials passed on the command line and then posts the message you provided:
// First, we need to import the `request` module, which will allow us to make HTTP requests to the Hacker News API
const request = require('request');
// Next, we need to parse the username and password from the command line arguments
const username = process.argv[2];
const password = process.argv[3];
if (!username || !password) {
// If the username or password is not provided, print an error message and exit the program
console.log("Error: Please provide a username and password as command line arguments");
return;
}
// Now we can use the `request` module to make a POST request to the Hacker News login API endpoint
// In the request, we need to provide the username and password as part of the request body
request.post({
url: 'https://hacker-news.firebaseio.com/v0/login.json',
body: JSON.stringify({
"username": username,
"password": password
})
}, (error, response, body) => {
if (error) {
// If there is an error, print it to the console
console.log(error);
return;
}
// If the login was successful, the API will return the user's authentication token
// We need to save this token so that we can use it in subsequent requests
const authToken = JSON.parse(body).token;
// Now that we have the authentication token, we can use it to post a new message on Hacker News
// To do this, we need to make a POST request to the `item` endpoint, providing the authentication token as part of the request headers
request.post({
url: 'https://hacker-news.firebaseio.com/v0/item.json',
headers: {
"Authorization": `Bearer ${authToken}`
},
body: JSON.stringify({
"title": "Best Prompts for ChatGPT",
"text": "Fellow members, I'm curious to know what are some of the best prompts to use on ChatGPT to understand its full-fledged capability as a newbie developer. One of the things I noticed, is that it produces the requested code in the cleanest manner but it's not complete. For instance, I tried the prompt - \"give me the python code for TicTacToe Game\" and the code produced was incomplete. Have you all encountered the same or my prompt is inappropriate?"
})
}, (error, response, body) => {
if (error) {
// If there is an error, print it to the console
console.log(error);
return;
}
// If the request was successful, the API will return the ID of the newly-created post
const postId = JSON.parse(body).id;
console.log(`Successfully posted message with ID ${postId}`);
});
});
To use this code, you would need to save it to a file (e.g. hacker-news-post.js) and then run it from the command line, providing your username and password as arguments: