Build a ChatGPT Product

| 6 minutes read

A short while ago I saw this post on LinkedIn and found it funny.

GenAI Meme

Everyone talks about GenAI and ChatGPT but few people use it. Now I wanted to understand more of the capabilities of ChatGPT and thought I could build a small product from it.

In this blog post, I will describe how you can use ChatGPT to build your little product, how to do some prompt engineering and where the limits are.

What is ChatGPT

ChatGPT is an LLM (Large Language Model). So all it does is predict the next word based on statistics. It does not know anything or understand things. All it does, is predict the next word. But really well. If you ask ChatGPT what 10+15 is, it knows it is 25. Not because it understands maths, but because it saw it somewhere. If it sees 100 times 25 as a result and 5 times 20, it predicts 25. If it sees during the learning that it is 26 for 200 times, it learns it is 26. We are not there yet, that it knows math or programming. It just predicts. And this is also the limit at the moment.

If you ask it to summarize some text, it performs very well on that. Or rewriting text. But on calculations, not so well.

(But let’s see where we are going in the future 🚀).

How to use ChatGPT

In my example, I wanted to create a fitness app. I am tired of searching through endless pages to build my training plan for the gym. So why not use ChatGPT?

ChatGPT should be very good in tasks like this. So I could just let it build my training plan based on my input. But having it for me wasn’t enough, so I wanted to build a product around it. Having a backend, doing the requests and a frontend presenting it.

(Disclaimer, I never released it, because it worked and for releasing it I had to implement some payment and my point was proven, I could build it 🤣)

Getting started with ChatGPT

The first few attempts were quite wrong. I asked to build the training plan and it came up with repetitive and boring stuff. Also, I wanted to use the API in the future with a frontend, so I provided the JSON format. The problem is, that it doesn’t use it all time. Here is a bad example response:

Generate a workout training plan.
Context:
I have a gym available
I want to train 5 times a week
I am on a vegan diet
I want to lose weight
I am a men
I weigh 80kg
I am 180cm in height

Response in the following format:
{"weekday": "training"}[]

Response:

Monday: Cardio (45 minutes)
Tuesday: Weight Training (45 minutes)
Wednesday: Yoga (30 minutes)
Thursday: Plyometric Training (45 minutes)
Friday: HIIT (30 minutes)

So it didn’t work on the first few attempts. But with some prompt engineering, it worked quite well:

create a detailed workout training plan with exercise, repetition and weight. return between 5 and 8 exercises per training day.
I have a gym available
I want to train a maximum of 5 times a week
I want a maximum of 8 exercises per day
I am on a vegan diet
I want to gain muscles
I am a men
I weigh 80kg
I am 180cm in height

Response in this JSON format
Units should be metric
you can only answer in JSON format
use the Exercise interface format for the response and return an array of exercises [Exercise]
interface DayDetail = {"exercise" : string, "repetition": string, "weight": string}
interface Exercise = {"day": "monday|tuesday|wednesday|thursday|friday|saturday|sunday", details: [DayDetail]}

Important here is, that you have to explain ChatGPT, that it has to use the JSON format, as well als how the interface looks like.

The response then looked like this:

[
  {
    "day": "Monday",
    "details": [
      {
        "exercise": "Squats",
        "repetition": "3 sets of 8-12 reps",
        "weight": "50kg"
      },
      {
        "exercise": "Barbell Row",
        "repetition": "3 sets of 8-12 reps",
        "weight": "50kg"
      },
      {
        "exercise": "Leg Press",
        "repetition": "3 sets of 8-12 reps",
        "weight": "90kg"
      },
      {
        "exercise": "Incline Dumbbell Press",
        "repetition": "3 sets of 8-12 reps",
        "weight": "30kg"
      },
      {
        "exercise": "Upright Row",
        "repetition": "3 sets of 8-12 reps",
        "weight": "30kg"
      },
      {
        "exercise": "Lateral Raise",
        "repetition": "3 sets of 8-12 reps",
        "weight": "15kg"
      },
      {
        "exercise": "Cable Tricep Extension",
        "repetition": "3 sets of 8-12 reps",
        "weight": "20kg"
      },
      {
        "exercise": "Cable Bicep Curls",
        "repetition": "3 sets of 8-12 reps",
        "weight": "20kg"
      }
    ]
  },
  {
    "day": "Tuesday",
    "details": [
      {
        "exercise": "Deadlift",
        "repetition": "3 sets of 8-12 reps",
        "weight": "90kg"
      },
      {
        "exercise": "Bench Press",
        "repetition": "3 sets of 8-12 reps",
        "weight": "60kg"
      },
      ...
      ]
  }
  ...]

Backend

This API is easy to use with some go code:

package main

import (
	"context"
	"encoding/json"
	"fmt"
	openai "github.com/sashabaranov/go-openai"
)

func getPromptString(trainingsRequest *TrainingsRequest) string {
	return `THE PROMT FROM ABOVE -> Depending on your parameter, this should change`
}

func getTrainingsPlan(trainingsRequest *TrainingsRequest) []TrainingsResponse {
	var trainingsResponse []TrainingsResponse
    fmt.Println("Start GPT request")
    client := openai.NewClient("YOUR TOKEN FROM .ENV")
    ctx := context.Background()
    req := openai.CompletionRequest{
        Model:     openai.GPT3TextDavinci003,
        MaxTokens: 2048,
        Prompt:    getPromptString(trainingsRequest),
    }
    resp, err := client.CreateCompletion(ctx, req)
    if err != nil {
        fmt.Printf("Completion error: %v\n", err)
        panic(err)
    }

    fmt.Println("Start parsing of response")
    fmt.Println(resp.Choices[0].Text)

    responseError := json.Unmarshal([]byte(resp.Choices[0].Text), &trainingsResponse)
    if responseError != nil {
        fmt.Println(responseError)
        panic(responseError)
    }
	return trainingsResponse
}

Frontend

This was built in Elm and is super boring, so I won’t show it here 😅

Conclusion

It is fairly easy to build a product using ChatGPT. But offering it for free is an easy way of burning money. One request for creating a training plan costs around 10ct. So be careful with whom you share your page.

But all in all, it is a lot of fun playing around with these models. I am super excited about what the future brings us, but at the moment, we shouldn’t be worried about losing jobs against LLMs but flooding the internet with crappy content even more.

So familiarise yourself with GenAI, use it in your workflow where it helps (like rewriting emails or similar) and be careful what you do with the content. Please don’t fill the internet with 💩 posts or 💩 content, but enhance your current work with it. I think ChatGPT won’t go away so fast.

If you want to support this blog, you can buy me a coffee ☕️ or sign-up for my newsletter ✉️

comments powered by Disqus