If you haven’t lived under a rock last weekend, then you must have heard about ChatGPT. After seeing some impressive tweets and seeing a blog post trending on HackerNews about it, i had to try it out! If you want to try it out, you can do it. All you need is to create an account on openai.com and go to chat.openai.com.

Let’s build a WebApi in F# by just using prompts. This is my Conversation with ChatGPT. The questions are mine, the answers are from ChatGPT (click the to see the answer):

Recap

I think that’s enough to give you an impression. I am very impressed by this and i am quite happy with the outcome. There were some instances, where the answer would just stop in the middle of the sentence. Here is an example:

Screenshot 2022-12-04 at 23.31.01.png

This is due to the fact, that the answers are limited to a certain length.

Does the produced code that actually works? No. For example the webapi is not valid Giraffe code:

        // Create a route for the GET /users/{id} endpoint
        route GET "/users/{id:int}" (fun (id:int) ->
            // Find the user with the specified ID
            let user = users |> List.tryFind (fun u -> u.Id = id)
            // Return a 404 response if the user was not found
            match user with
            | Some user -> OK user
            | None -> NotFound "User not found"
        )

But the Model is correct:

// Define a type to represent a user
type User =
    { Id: int
      Name: string }

// Define a list of users
let users = [ { Id = 1; Name = "Alice" }
              { Id = 2; Name = "Bob" }
              { Id = 3; Name = "Charlie" } ]