Sorting NFT Art with MakerSuite and PALM API
Tags: googlecloud, ai
Published: 2023-09-30 16:11:18

At [rc.xyz](https://rc.xyz/) we sort out hundereds of thousands of NFT Artworks so the artists have nice and clean portfolios of their work. However, sometimes it's hard to convert the logic into the code, so let's use the help of Google MakerSuite and PALM API! 

We won't dive deep into what [MakerSuite](https://www.youtube.com/watch?v=Ce1AOchQMzA) or [PALM](https://www.youtube.com/watch?v=yAANQypgOo8) is, if you are interested, please watch the linked introduction videos!

## Getting started
![MakerSuite intro screen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr9n7uyjgn3m8yfcbz4m.png)

MakerSuite offers several ways for interacting with the API, for our use-case, we will use the **Data prompt**, since it gives us a UI to create a prompt with few examples more easily.

**First version of our prompt:**
```You are a category classifier, your job is to decide whether the items match together and if so, generate suitable category name. You output JSON with value valid: boolean and optionally name: string if valid is true.```

**We are using few tricks to make our prompt perform better:**
- Giving the LLM instructions about what it is supposed to do
- Describing desired output structure (JSON with types like string and boolean)
- Describing what choices it should made

**Examples:**

![Examples text is provided in the prompt link at the end](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ou0zywyjfuvrphwxr3d.png)


_Tip: You can import/export examples right from the MakerSuite, under the Actions button_


![MakerSuite action button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ln32ulnlwcz9fgv6sey.png)

## Testing
MakerSuite enables us to test our prompt with multiple test fields at once, so we don't have to call the API again and again, let's try it out with some cases we have not used in the testing data. 


![Test cases](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qa3hzw9h73x6lstxmskb.png)

And after running the prompt:

![Finished generation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/15jacw630wjsbpfk94on.png)

Which is in line with what we expect, great! 

## Implementation

MakerSuite offers you to export the code snippet right from the web UI, which includes the full formatted prompt along will the other model settings. 


![Code export](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tonwd315meta46u5tznc.png)

While the JS snippet suggest installing helper packages, it's still fully possible to use just fetch with the API key, since there isn't any complicated auth process as with most of the Google APIs. Thanks to minimal dependencies, it can run anywhere in your backend, like in [Firebase Cloud Functions](https://firebase.google.com/docs/functions/).

As with any Generative AI stuff, we highly recommend adding human in the loop to verify that the results are valid and revert them if not. 

You can view the full prompt thanks to [MakerSuite sharing here.](https://makersuite.google.com/app/prompts?state=%7B%22ids%22%3A%5B%2214gdZpSKg5X_FtNHu43UuxRrz1j0-9TtJ%22%5D%2C%22action%22%3A%22open%22%2C%22userId%22%3A%22101375204923275298044%22%2C%22resourceKeys%22%3A%7B%7D%7D&usp=sharing)