[Build with Haskell] How it was implementing a code agent in Haskell

This page summarizes the projects mentioned and recommended in the original post on /r/haskell

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • wasp

    The fastest way to develop full-stack web apps with React & Node.js.

  • Here is all the Haskell code related to this project: https://github.com/wasp-lang/wasp/tree/wasp-ai/waspc/src/Wasp/AI , I hope some of you find it interesting to see how some of these things were done, and I would also love to hear any advice/feedback on what we could have done better (I still consider myself new to Haskell in many ways).

  • HMock

    Mock framework for testing in Haskell

  • How was it implementing this in Haskell: - As usual, the part I liked the best about doing this in Haskell was just the safety that Haskell gives me - I would sometimes go for a whole day without ever running a program since the compiler and types are there for me to guide me, both while writing new code and while refactoring. - I also have to compliment HLS, it has really improved in the last years and it is hard for me to imagine I would have to go back to ghcid - not just because of live error reporting, but also because of all the help with automatically adding and removing imports. - I was afraid that it will be hard to interface with OpenAI API, but they designed really simple HTTP API, at least for using the ChatGPT, and a combination of Aeson and Haskell’s ADTs made it a very pleasant experience (I quite enjoyed modeling their API via ADTs!). You can see the code for this here, it is just one file: https://github.com/wasp-lang/wasp/blob/wasp-ai/waspc/src/Wasp/AI/OpenAI/ChatGPT.hs . - While I am still a tiny bit afraid of using monad transformers, I enjoyed writing my own stack, for the abstraction called CodeAgent. Among other things, I used ReaderT to pass it a strategy for writing generated code to files, which made it very easy to use CodeAgent both for generating files to the disk and for sending them to stdout, depending on the different use cases that we needed to support. Code: https://github.com/wasp-lang/wasp/blob/wasp-ai/waspc/src/Wasp/AI/CodeAgent.hs . - Haskell has no built-in multiline strings, which was looking like it will be quite a problem since we had to write quite big prompts for GPT, but neat-interpolation package saved the day with its [trimming| .... |] quoter, which not only allows multiline strings, but also trims them nicely and allows for interpolation. I will be using it from now on for any somewhat bigger multiline string in Haskell! - I also wanted to give kudos to pretty-simple package. I often use Debug.trace for debugging, but it doesn’t print ADTs nicely, and it can be very hard to debug then. pretty-simple has a ptrace function that not only formats almost any reasonably looking string by common-sense delimiters, but even colors it reasonably! It made a huge difference for us and enabled us to easily print out big GPT prompts and HTTP response and requests while making them super readable, with no work at all needed on our side. - I implemented a function for retrying an IO action until it succeeds or fails more than a defined amount of times. I am normally a bit afraid of testing IO code, but decided to try the MonadSomething approach and enjoyed doing it! I guess it helped that function was quite simple. I am keeping my eye on https://github.com/cdsmith/HMock package, I would like to learn how to use it and stick with it for use cases like this in the future, but didn’t have time at the moment. - The only bad thing that I can think of is a bit of trouble I had with a httpJSON function, where I wasn’t aware that it doesn’t throw an HttpException if status is not 2xx. It did have that behaviour before, but that changed with version 5.something, and I must have read some old piece of docs somewhere that said that it always throws those exceptions, and got bitten by it. Exceptions are still somewhat of a tricky part for me in Haskell. I wish there was a more formal way to indicate when and which exceptions are thrown by which function - but I guess that is hard/impossible to encode in the type system. What would also help would be more details on where the exception happened, in which part of the code → I am guessing that is also probably hard to achieve in Haskell due to its lazy nature.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Using Wasp to Build Full-Stack Web Applications on Koyeb

    2 projects | dev.to | 2 May 2024
  • 🥇The first framework that lets you visualize your React/NodeJS app 🤯

    1 project | dev.to | 23 Apr 2024
  • Ask HN: What's a batteries-included framework that's React-first?

    3 projects | news.ycombinator.com | 18 Apr 2024
  • Garden – The Design System by Zendesk

    1 project | news.ycombinator.com | 7 Mar 2024
  • Wasp – Rails-Like Framework for React, Node.js and Prisma

    1 project | news.ycombinator.com | 30 Jan 2024