Can AI help me find the perfect breed of dog?

Jun 12, 2024 by Stein Ove Helset
Can AI help me find the perfect breed of dog?

I'm thinking about getting a dog, and I was wondering whether or not GPT4 and GPTscript could help me figure out the perfect dogbreed for me. So, I set out to build a script and a simple website that would allow anyone to input some information about themselves, answer a few questions, and find out what our future AI overlords think would be the perfect dog for me. Would it recommend a massive great dane, or determine a pug would be a better fit.

I've written all of this up as a tutorial, so you can follow along and build your own version if you'd like. I'm using GPTscript to simplify the logic, and because it allows for building my mini-app using just natural language, and I don't want to try and learn all the complexities of langchain and work in python. This should be less than an hour of my time.

The GPTscript is going to let me create some inputs, like where I live, any allergies, my level of activity, family size, etc.

When the script is running, it will find 5 breeds that it would recommend and generate a list with these. The list will contain information in a simple pros/cons list, and it will also include a picture of the dog.

Setting up GPTScript

First, I needed to set up GPTScript on my computer to get started. It's a small runtime and this should just take a few minutes.

A short guide:

  1. First you install the CLI (Command line interface) by running this command:
MacOS / Linux: brew install gptscript-ai/tap/gptscript Windows: winget install gptscript-ai.gptscript
  1. Now, to power of GPTscript we need an LLM. I'm using OpenAI and I already have an API key. But if you don't, you can get your OpenAI API key by going here (https://platform.openai.com/api-keys). You'll need to sign up for an actual acount.

  2. Next we need to add the API key to our environment. You do that by creating an environment variable, which is done by running this simple command:

MacOS / Linux: export OPENAI_API_KEY="your-api-key” Windows: $env:OPENAI_API_KEY = 'your-api-key'

Voila. Now we should be ready to jump to the next step . If my instructions for getting started wtih GPTscript and OpenAI were insufficient, fear not, you can can go to the official getting started guide for GPTScript by clicking here (https://docs.gptscript.ai/getting-started).

Prices

GPTScript is opensource and free, but we'll need to pay a bit for our OpenAI usage. So, just for reference, it might be smart to take a look at the price lists here: https://openai.com/pricing

Using OpenAI’s API is not free, but you do only pay for what you actually use, which in this case should be a tiny amount.

The script we are building in this tutorial will use a language model called GPT-4 Turbo. The prices can vary a little bit based on what you actually are sending in to the GPTscript, how long the texts are, etc.

Take a good look at the price lists to familiarize yourself with them. (You have now received your obligatory cost warning!)

Creating the script

To create my dog breed recommendation GPTScript, I need to create a new file called

dogbreeds.gpt
. This can then be run using this command:

$ gptscript dogbreeds.gpt

This will of course not do anything yet.

So let's open up the file in an editor, and start adding the logic that will tell the system what to do.

First, I'm going to add the following content:

tools: sys.write, sys.http.get description: Analyzes the description and find suitable dog breeds. args: description: The description to analyze and find dog breeds with. Perform the following commands in order: 1. Analyze the description and find 5 suitable dog breeds that can fit what the users is looking for. 2. Generate a HTML with the 5 dog breeds. For each of the dogs, add an explaination to why each of them is a good fit and why they are a bad fit. 3. Save the HTML to a file at `dogbreeds.html`.

In this first version of the script, I'm keeping it simple, so I'm not including the images of the dog breeds. But let's break down the code and go through what's happening:

-First, we include a set of tools we are going to use: "sys.write": This is used to write data to files in our system. "sys.http.get": This is used to access a browser to find information. -Next, we set up a description for the script. -And the last "configuration" is which arguments we are going to accept. In this script, we and an agrument called "Description". This is the description that users are providing and that GPTScript is basing everything on.

Below the configuration for our script, I set up a few commands that the script should go through.

Alright, let's try running this command. Remember that now we need to provide the description argument. It can be something like this:

$ gptscript breedfinder.gpt --description "I'm looking for a dog that does not bark a lot. My girl friend can be allergic to dogs. We like to hike. We do not have small children."

If you run this command, you will notice that a new HTML file will appear in the same folder as your script. Try opening it a browser. It should look something like this:

dogbreeds_1.jpg

The overlords have spoken! My gut tells me I'm not a poddle kind of guy, but the labradoodle sounds pretty good. Still, it would be nice if it provided some pictures so I could see what these dogs looked like. Let's update our script and get it to add some images.

Adding images

To make the script access Google to find images of the dogs, we need to make the following changes:

tools: sys.write, sys.http.get description: Analyzes the description and find suitable dog breeds. args: description: The description to analyze and find dog breeds with. Perform the following commands in order: 1. Analyze the description and find 5 suitable dog breeds that can fit what the users is looking for. 2. For each of the 5 breeds, go to https://google.com. Search and find the url for a picture of the breed. 3. Generate a HTML with the 5 dog breeds. For each of the dogs, add an explaination to why each of them is a good fit and why they are a bad fit, and insert the url for the image. 4. Save the HTML to a file at `dogbreeds.html`.

Ok - here's what I changed in detail:

  1. I added a new step between 2 and 3 where I instruct the script to go to Google, and find a picture of each of the dog breeds. The url for the images should be stored temporarily.
  2. A changed step 2 (now step 3) a little bit. At the end of that step, I instruct the GPTScript to insert the url to the image for each of the dogs.

No I can run this again and find out what these pups look like To do that, just go back to the terminal and run the same command again. The result should look something like this:

dogbreeds_2.jpg

Well the AI seems to have changed it's mind, now it's added a Basenji to the list. I've never heard of this breed, but apparently it doesn't bark. I'm guessing it's not an ideal watch dog, but that's not what I told the AI I was looking for. That Labradoodle is pretty cute though, I think we may have a winner.

Summary

Hopefully you've been able to follow along with all of this. You should now have a simple script that will find dog breeds for you. This approach can be used for a lot of other use cases as well, maybe you want to find the perfect burger, surf board, or flip flops.

As a little task, try changing the script a little bit to find cat breeds instead of dog breeds. Hope you had fun, and join the GPTscript Discord if you're looking for any help.

Stein Helset is a developer who creates tutorial videos to teach coding, with a focus on Django, Python, Vue, Htmx and much much more!