News for hackers. Stuff that matters.
Re:How to generate tested software packages using LLMs, a sa... by ramesh31 on Monday August 07, 2023 @08:15PM (#37042782)
>What is the most difficult thing you’ve gotten it to do?

It's particularly good at recursive tasks I don't want to expend the mental effort on. I.e:

  Llama: I am Llama, a programming assistant. Please provide me with a task.

  User: Thanks. Here is a data structure. Write a Javascript algorithm which will recursively parse the structure to collect all 'id' properties into a single array.
  Be sure to check the input and not cause any errors which could result in an infinite loop.

  ```
  const data = {
    'id':'test1',
    'nodes':[
     {'data':{}, 'list':[{'id':'test2', 'values':[{'id':'test3', 'name':'val'}]}]}
    ]
  }
  ```

  Llama: Sure thing! Here is the algorithm in Javascript:

  ```
  function parseId(data) {
    const idArray = [];

    // Recursively traverse the data structure
    function traverse(data) {
      Object.keys(data).forEach((key) => {
        if (key === 'id') {
          idArray.push(data[key]);
        } else if (typeof data[key] === 'object') {
          traverse(data[key]);
        }
      });
    }

    // Start the recursion
    traverse(data);

    return idArray;
  }

  parseId(data) // Output: ["test1","test2","test3"]
  ```
...and I even just learned something new here, that Object.keys can operate on arrays.

There are no comments on this comment yet.