News for hackers. Stuff that matters.
Re:Canvas is a new way to write and code with ChatGPT by rglover on Thursday October 03, 2024 @04:06PM (#41734418)
If you prefer to support Claude, check out Parrot [1]. I'll be adding a feature similar to this backed by Claude 3.5 Sonnet over the next few weeks.

[1] https://codewithparrot.com

Re:Canvas is a new way to write and code with ChatGPT by elashri on Thursday October 03, 2024 @04:28PM (#41734631)
In your landing page it says about competitors

> They're not wasting hours trying to "figure out" a solution

I am pretty sure that we don't have AGI that would figure our solutions to our problems (coding or not) on its own yet. And from experience, you would need to solve the problems at least conceptually before using LLM and try to get something useful out of that.

Re:Canvas is a new way to write and code with ChatGPT by rglover on Thursday October 03, 2024 @04:41PM (#41734759)
Depends on scope, but Parrot is tuned to decently one-shot a lot of stuff.

For example, I need to implement HTTP/2 in my JS framework and was curious about what the code would look like. Here's the result from the following prompt: https://www.imghippo.com/i/xR2Zk1727987897.png (full code it gave me here: https://gist.github.com/rglover/069bdaea91c629e95957610b484e...).

Prompt:

> Help me implement an HTTP/2 enabled server using Express.js.

---

When I initially researched how to do this just following the Node.js docs, Google results, and SO, it was fairly confusing (easily wasted an hour or two). This immediately gave me what I needed to understand the approach in a few seconds.

Re:Canvas is a new way to write and code with ChatGPT by elashri on Thursday October 03, 2024 @04:57PM (#41734914)
I am not a nodeJS developer but it was interesting that the first results from a kagi search was SO question that had one of the answers that contains a code very similar to what you provided here [1]. So while you might be right in general, I still think you still gave an example of that you used LLM tool to help implementing a solution. You actually knew that you want to implement http/2 using express.js.

Hint: I am not sure whether this is a good solution or not. As I said I am not a nodeJS developer.

[1] https://stackoverflow.com/questions/59534717/how-to-integrat...

Re:Canvas is a new way to write and code with ChatGPT by rglover on Thursday October 03, 2024 @05:06PM (#41734994)
If you want to take it for a test drive, Parrot is free to try and works with any language (~200+ languages and frameworks supported), not just JS/Node. I'd also be happy to give you some extra generation tokens to push the limits (just email me w/ your username [email protected] and I'll hook you up) and see if it'd be useful.
Re:Canvas is a new way to write and code with ChatGPT by nh2 on Thursday October 03, 2024 @09:32PM (#41736932)
That's probably the most FOMO driven landing page I've seen so far! I'll bite:

    Your competition is using AI to build their product right now.
    They're not writing code by hand.
    They're not Googling code answers on StackOverflow.
    They're not wasting hours trying to "figure out" a solution.
Extraordinary claims require some investigation!

Let's see how far I get without "Googling answers".

Spoiler: If the competition uses such AI that, good for me!

(Note I don't want to pick on Parrot here; from my first 5 minutes with the tool, it's /fun/, has a nice UI, a good idea for iteration, and somebody has to build such tools to make them work eventually even if they don't work great today yet. I wish it lots of success. But I want to also point out examples of the practical limitations of all such tools, and state that I highly doubt that they today can _in any way_ replace a human programmer who knows what they are doing, and has the awesome skill to use Google, StackOverflow, and "figure out" things.)

Prompt:

    I need a Haskell function that hashes a given file (FilePath)
    with the blake3 hash function.
    It is important that it works on large files (e.g. 100 GB)
    without freezing the Haskell runtime.
Output:

    import qualified Crypto.Hash.BLAKE3 as BLAKE3
    import qualified Data.ByteString as BS
    import System.IO (withFile, IOMode(ReadMode))

    hashFileBLAKE3 :: FilePath -> IO BS.ByteString
    hashFileBLAKE3 filePath = do
      let chunkSize = 8192  -- 8KB chunks
      withFile filePath ReadMode $ \handle -> do
        let loop ctx = do
              chunk <- BS.hGet handle chunkSize
              if BS.null chunk
                then return $ BLAKE3.finalize ctx
                else loop $! BLAKE3.update ctx chunk
        loop BLAKE3.init
Explanation:

    This Haskell function, `hashFileBLAKE3`, calculates the BLAKE3 hash of a
    given file. It's designed to work efficiently with large files without
    freezing the Haskell runtime. Here's a step-by-step explanation of how it
    works:

    1. We import necessary modules: `Crypto.Hash.BLAKE3` for the BLAKE3 hash
       function, `Data.ByteString` for efficient byte handling, and `System.IO`
       for file operations.

    2. The function takes a `FilePath` as input and returns an `IO ByteString`
       containing the hash.

    3. We define a `chunkSize` of 8192 bytes (8KB) for reading the file in
       manageable chunks.

    4. The `withFile` function is used to safely open and close the file,
       ensuring proper resource management.

    5. Inside the file handling function, we define a recursive `loop` that
       reads the file in chunks:
       - It reads a chunk of the file using `BS.hGet`.
       - If the chunk is empty (end of file), it finalizes and returns the
         hash.
       - Otherwise, it updates the hash context with the new chunk and
         continues the loop.

    6. The loop starts with `BLAKE3.init` to create the initial hash context.

    7. By using lazy evaluation (`$!`), we ensure that the hash context is
       strictly evaluated in each iteration, preventing memory buildup.

    This implementation is memory-efficient and can handle very large files
    without issues, as it processes the file in small chunks rather than
    loading it entirely into memory.
My remark:

    * This solution is already pretty good.
    * The explanation is also useful for people new to Haskell
      or this type of task.
    * Some explanations are subtly wrong, e.g. `$!` is the
      _opposite_ of lazy evaluation, and the sentence
      is contradicting itself.
    * It mainly got the imported module name wrong
      (should be `import BLAKE3` from
      https://hackage.haskell.org/package/blake3).
      Let's see if it fixes it when I tell it what I'd observe
      when trying to compile the code.
      A simple Google search for "haskell blake3" should point out the correct name.
Corrective prompt:

    The mentioned `Crypto.Hash.BLAKE3` module doesn't exist as a Haskell library.
Output:

    import Crypto.Hash (hash, Blake2b_512, Digest)
    import qualified Data.ByteString as BS
    import qualified Data.ByteString.Lazy as LBS
    import System.IO (withFile, IOMode(ReadMode))

    hashFileBLAKE2b :: FilePath -> IO (Digest Blake2b_512)
    hashFileBLAKE2b filePath = do
      let chunkSize = 8192  -- 8KB chunks
      withFile filePath ReadMode $ \handle -> do
        let loop acc = do
              chunk <- BS.hGet handle chunkSize
              if BS.null chunk
                then return $ hash (LBS.fromChunks acc)
                else loop (chunk : acc)
        loop []
My observation:

    * I asked for BLAKE3, but now it implemented BLAKE2B.
    * The solution is very wrong.
      It splits the file into _reversed_ chunks and then hashes them.
      The error is subtle and will be hard to debug.
So I'm quite sure I wouldn't allow anybody to build my "product" with such tools yet.

But it certainly is fun and there's definitely some usefulness in there, especially for learning general concepts that are well understood.

I guess in the end it's this: Programmers don't need to "roughly get it right" (which is what current tools do well) when it comes to products. They need to get it /precisely/ right.