Using ChatGPT for developping an app?

`Hey there.

The whole world is going crazy about this “new” AI called ChatGPT. Someone even had it programming their own vst-plugin for some audio-stuff.

So I got curious and asked ChatGPT if it would write me some fitting code for some imaginary new app where you can create individualized shares for the same folder/file for multiple users.

this is what the AI gave me. Suggested app-title Personalized Links. AI told me that this is made for an SQL-databaseusing a SHA256-Hash-algorithm.

<?php

namespace OCA\PersonalizedLinks\Controller;

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\IDBConnection;

class LinkController extends Controller {

  private $db;

  public function __construct($appName, IRequest $request, IDBConnection $db) {
    parent::__construct($appName, $request);
    $this->db = $db;
  }

  /**
   * Generates a personalized link for a file and saves it in the database
   * @param string $fileId The ID of the file
   * @param string $username The username of the user
   * @return JSONResponse
   */
  public function generateLink($fileId, $username) {
    $link = hash('sha256', $fileId . $username);
    $query = $this->db->prepare('INSERT INTO `*PREFIX*personalized_links` (`file_id`, `username`, `link`) VALUES (?, ?, ?)');
    $query->execute([$fileId, $username, $link]);
    return new JSONResponse(['link' => $link]);
  }

  /**
   * Returns the personalized link for a file
   * @param string $fileId The ID of the file
   * @param string $username The username of the user
   * @return JSONResponse
   */
  public function getLink($fileId, $username) {
    $query = $this->db->prepare('SELECT `link` FROM `*PREFIX*personalized_links` WHERE `file_id` = ? AND `username` = ?');
    $query->execute([$fileId, $username]);
    $link = $query->fetchColumn();
    return new JSONResponse(['link' => $link]);
  }
}

Further on I asked for a frontend-implementation of that code and this is what ChatGPT gave me

OCA.PersonalizedLinks = {
  generateLink: function(fileId) {
    $.ajax({
      type: 'GET',
      url: OC.generateUrl('/apps/personalized_links/link/generate/' + fileId),
      success: function(response) {
        // Display the personalized link
        console.log(response.link);
      }
    });
  },
  getLink: function(fileId) {
    $.ajax({
      type: 'GET',
      url: OC.generateUrl('/apps/personalized_links/link/get/' + fileId),
      success: function(response) {
        // Display the personalized link
        console.log(response.link);
      }
    });
  }
};

I then asked the machine to make a real app from it.

To use the code described above as a Nextcloud app, you need to follow these steps:

Create a directory for your app. You can name it for example personalized_links.

Create an info.xml file, in which you provide basic information about your app such as the name, version and dependencies. Here is an example for the info.xml file


<?xml version="1.0"?>
<!--

Nextcloud app info.xml file

-->
<app>
  <id>personalized_links</id>
  <name>Personalized Links</name>
  <description>Generate personalized links for shared files</description>
  <version>1.0.0</version>
  <requirements>
    <php>
      <minVersion>7.0.0</minVersion>
    </php>
  </requirements>
</app>
  1. create a routes.php for your API routes, e.g.
<?php

declare(strict_types=1);

/** @var \OCP\Route\IRouter $router */
$router->get(
  '/apps/personalized_links/link/generate/{fileId}',
  function (int $fileId) {
    // Generate the personalized link here
    $link = 'https://your-nextcloud.com/s/' . $fileId . '/' . uniqid();

    return new \OC_OCS_Result(['link' => $link]);
  }
);

$router->get(
  '/apps/personalized_links/link/get/{fileId}',
  function (int $fileId) {
    // Retrieve the personalized link here
    $link = 'https://your-nextcloud.com/s/' . $fileId . '/' . uniqid();

    return new \OC_OCS_Result(['link' => $link]);
  }
);
  1. Create a js file for your frontend code. Here is an example for the personalized_links.js file:

OCA.PersonalizedLinks = {
  generateLink: function(fileId) {
    $.ajax({
      type: 'GET',
      url: OC.generateUrl('/apps/personalized_links/link/generate/' + fileId),
      success: function(response) {
        // Display the personalized link
        console.log(response.link);
      }
    });
  },
  getLink: function(fileId) {
    $.ajax({
      type: 'GET',

So how is that? What do you think? Would it work like that?

1 Like

I am not proficient enough in Nextcloud App development to say if this will work or not just from reading the text but you can always setup a development environment and give it a try and see if it works :slight_smile:

Here is a compose file for Nextcloud App development using Docker by @juliushaertl you can use to give it a try

A regular compose file with Nextcloud works too but you’ll have to mount the skeleton app into /var/www/html/custom_apps/app_folder_name and afterwards change the owner to www-data inside the container and restart the container afterwards before it works.

Change permissions like so:

  • docker exec -it <container-id> chown -R www-data /var/www/html/custom_apps/app_folder_name
    Or
  • docker compose exec -it <service-name> chown -R www-data /var/www/html/custom_apps/app_folder_name

This changes the permissions of the folder locally too when its mounted so you’ll have to change that back to your regular user afterwards when you’re done to get the permissions back to normal on the folder.

2 Likes

Thanks for your very valuable input here.

But for me personally this is more like a feasibility study… I would like to go on guessing and thinking from that point on into: how could one use ChatGPT for activly “developping” code for NC, etc.

So I don’t really need to test that code but only someone telling me: that looks like it could work. Or: complete nonsense, stay away from it.

1 Like

Well from my limited knowledge it looks like it could work but I still have limited experience with Nextcloud App Development at this time so hard for me to say

I do know however that code generated from ChatGPT isn’t always on point and can often produce errors, I’ve already tried this with a couple languages and various functions :smiley:

Languages I’ve tried are: Java, JavaScript, Python and Bash

ChatGPT is great for getting started with your code or giving you hints or directions but it’s ultimately up to you to follow through on that and see if it works or if it is a reasonable way to do it or not.

Now you can always feed it back the errors you are receiving and it will amend the code until it eventually works, but that still leaves the question of “Is this a feasible way of implementing this feature/app/function in code?” which ultimately has to be answered by you, the developer.

Even if you ask ChatGPT about this, you will still have to know what questions to ask for it to answer them :smiley: and unless you specified your question with these things in mind it will not spit out code that takes these things into account.

Another point is that ChatGPT is also confident when it is in fact wrong, this is also something you have to follow up on and assert whether the answer you’ve been provided is, in fact, correct & functional or not.

You can still have ChatGPT give you lots of assistance in this area though, but important to remember the code it spits out doesn’t always work, the more complex a feature it’s implementing the less likely it is to work right away, you can increase this by improving the question with specifications or using the thread mode and having a continuous conversation with it upon which it will improve the code and make it more accurate and “functional” as you feed it more input & data.

My take is that it will probably be a great asset for assistance with code development (and other areas too), especially if you need someone to talk to and ask questions but don’t have anyone around for that or such similar things, but it’s ultimately not a replacement (at least not yet) for the developer implementing the code.

Because even if you just use the code it spat out after feeding it all the errors until it finally works, you will still need to assess whether this is a good implementation or not and other such things.

2 Likes

whoa… great input here.

And you find me surprised… I mean I know that not everything from ChatGPT is correct but as I thought coding/programming is a exact work with clear definitions and input it would be easy to get a correct code from that machine. Didn’t take into account that it’s only a dumb machine and not “intelligence” at all. Even not with exact coding.

Thanks for all of those insights!

1 Like

Hello I want to throw in my 50 ct about this as well:

The ChatGPT is a chat bot it was never intended to be used as a programming tool (in any sense). It might be tempting to use it to generate source code, especially for the uneducated or beginners. It promises to allow sort of low-code to no-code approaches to become true.

However, please keep in mind that you are still responsible what happens on the server! So, one thing is syntactically or semantically wrong code. This is something that can be tested by hand quite fast. No problem there.

When it comes to code quality it is another story:

  1. You will not easily get (useful) tests for your code. Thus, the complete code seems brittle at best.
  2. Architecture: A well-thought architecture makes the basis for good software. You can hack together all kinds of crazy stuff. Without a good and clear architecture, you will end up with a mess of code that is no longer maintainable.
  3. Security: Who is/feels responsible for the secure operation of the newly generated app? You need to understands the bits and pieces in the code.

So, long story short: I do not see in the nearer future the option to migrate the coding to ChatGPT and throwing out some app in a quick manner. I fear that some guys will do this and risk the effort and reputation of the community/company.
In fact, they are responsible according to the app store terms of service. But they might not even be aware of their duty.

2 Likes

Hey @christianlupus
Thanks for your wellthought input here.

I dunno if this is true. I asked the system if it knows NC and it told me latest version it was trained on was NC 20. So maybe it was intended as a chatbot at first. But then at a later point it must have grown into something different because if you’d use it as a chatbot only, why it would know about software projects in detail? Just to chat about it? :thinking:

vs

An uneducated or beginner “dev” would never think about how well-thought an architecture for their app might be neccessary, at first.

the company isn’t in charge for 3rd party apps. and will never be. And, to be honest, there already ARE 3rd party apps that aren’t well maintained… so that’ll always be a general problem with softwareprojects in open source worlds.
Does the community has a reputation?

So I think your comment is aiming to a different topic all in all.
I mean all of your points are correct. But they mostly are more general than especially valid for chatGPT, only.

I think the biggest problem about using chatgpt-developed software for Nextcloud is that it is not allowed to use them in open source software iirc.

2 Likes

Maybe so. But only “dev” would know…

That is true but the required level of knowledge is lower with the ChatGPT approach than to create an app in the classical way. Thus, the risk of an inexperienced user opening a security hole seems higher in my opinion if you encourage non-devs to publish apps.
By the ChatGPT approach I fear this ratio will rise even higher than it is right now.

in the end it’s up to the user (admin) to decide which 3rd party app to install or not. He can only be sure about some basic tests that an app would go through but there’s never any guarantee on security holes.

BTW right at the moment NC runs a camapain to really encourage community members to get into developping on their own. There are detailed howtos available about getting such a project started easily.

1 Like

1 Like

ChatGPT is basically a stochastic parrot.
If you want a demonstration of its limitations, then watch the videos by the German mathematician, computer scientist and university lecturer at the Hamburg University of Applied Sciences (HAW Hamburg) Prof. Dr. Edmund Weitz on about the subject:
(duckduckgo search string: weitz+haw-hamburg+chatGPT !yt )
He has published two videos on the subject, which impressively demonstrate how limited the system is when it comes to more complex context (german spoken):

  • ChatGPT und die Mathematik
  • ChatGPT und die Logik

My experience is that you can quickly advise the ChatBot for code snippets, but that it is almost useless for larger projects over 500 to 800 lines of code.
Wait and see how this develops and, above all, what Deepminds (Alphabet aka Google’s) Sparrow will contribute to this development.
ChatGPT Plus already costs you $20/Month, speed of developement is hughe.

Here the answer of the parrot itself:

1 Like

i myself tested at my very first try how long it would take to generate an error on the machine. After 7 questions the goal was reached. so I know about limitations of ChatGPT.
But thanks anyways for your interesting input here.
Plus I like how you asked the machine itself… and how it answered :smiley:

1 Like