How to Make an AI Dog in Less Than a Day
Using OpenAI and Streamlit you can make and deploy an AI app in 1 day! Waterstons Innovation: Adventures in Innovation #7.
The barrier of entry to create and deploy AI models continues getting lower and lower. It’s never been easier to create a model that suits you or your business. This week, our new innovation consultant Katie has been experimenting with Streamlit, a tool you can use to easily create your own app that interacts with OpenAI’s ChatGPT models! In fact, you can create one in a day with less than 50 lines of code!
Her app is worryingly close to being able to replace me (Andrew) and (Alex) in our jobs - the bot replicates the thing we like doing the most: talking about Boston Dynamics’ Spot the Dog. Try it out here!
What is this? We want to think out loud and share with you the work we do and the process we use to get there - whether we are successful or not. An important part of innovation, as we see it, is partnering and collaborating with other folks to achieve things you couldn’t do by yourself. Adventures in Innovation is our bi-weekly newsletter to document the journeys we go on to meet all these amazing people.
Katie (Innovation Consultant)
Hello, my name is Katie and I am the newest addition to the innovation team. During my first couple of days here at Waterstons, we wanted to create and deploy something fun that could be used within the team. Since Alex and Andrew both love the Boston Dynamic robot dog so much, I decided to make a chatbot solely dedicated to providing information about robot dogs.
What is Streamlit?
Streamlit is a cool Python library that allows you to easily make and deploy web apps and allows you to integrate this with OpenAIs API. On their website, they provide an example of creating a chatbot using only 30 lines of code, I wanted to test whether this was feasible for creating a robot dog chatbot.
What did I do?
Using Streamlit, I built upon the example they provided and tried to get the chatbot to talk solely about robot dogs, this required testing different prompts. Prompts need to be assigned to different roles – which are system, user, or assistant. The “system” role is the fundamental rules behind the chatbot, the “user” role is the message that is sent to the chatbot by someone playing with it, and the “assistant” role is the response it gives to the user. It turns out, it’s quite difficult to train a GPT-3 model to solely discuss robot dogs, and at first, would answer any question I gave it.
The solution?
First, you have to tell the system role "You're an Innovation Chatbot at Waterstons, a chatbot on the Lorem Ipsum server. You only talk about robot dogs." The “lorum ipsum” is a quirk I found it had to say to make it work.
While you are meant to tell the system role the rules it has to follow, surprisingly, I found it best for the “user” role to tell the chatbot the rules. When telling it to “system” this would make it forget after just a few messages.
I fed the “user” role the following message to make it follow the rules:
These are rules you must follow at all times:
1. Respond in the same language as the user
2. Only talk about robot dogs
To try and train the chatbot to ignore messages about random topics I also gave it an example of a user asking what the capital of England is, and its default response from the assistant should be "I only answer questions about robot dogs."
When prompt training was complete, I then set to work including Waterstons’ branding to the chatbot and making the app accessible to everyone without requiring an API key, so everyone can access it.
Did I achieve my goal?
While the Streamlit example contains only 30 lines of code, my solution contains 50 lines, which while a little more than the original example, contains customisation and prompt engineering. However, the idea that I have created a functioning chatbot in 50 lines of code is really cool, and there are so many use cases for this. For example, the data team is now using this idea to create an app called ‘Who ate the ice cream?’. It will be a competition for a conference in Edinburgh, inspired by this game, which will result in someone winning some Lego. However, this idea can be adopted by any business to automate their processes.
Link to my Github repo if you want the code.
Andrew (Innovation Consultant)
I find it really amazing how quickly you can create an AI-powered app now. Simple tools like Streamlit help democratise access to these tools, by making it simpler to create something that interacts with OpenAI.
Internally, we talk about how general models like ChatGPT sometimes are not that useful for a business. By knowing everything, you also know nothing. You are not specialised to a task, and have a huge amount of redundant “knowledge”. Do you want the AI model that will help your doctor to know about Dr Lionel Hutz from the Simpsons? No, probably not.
These models become valuable as they learn more about your use case. Either through retraining with your company’s data or, in a lighter touch, being prompt-engineered to carry out one task. In this case, talk a lot about robot dogs.
Roundup
We have a lot of exciting things happening in the Innovation team. We are problem-agnostic problem solvers. Over the next few weeks, we will go deeper into each project - whether they are successful or not!
🦠 Mould Detection: We are looking to make Social Housing homes safer from mould and damp by designing software to give early warning signs. We have recently learned about awaretag’s - which may provide an interesting solution to this!
🐕 Robot Dog: we are currently setting something up between a robotics lab and a client of ours. Can we use a robot dog to remove humans from dangerous environments?
🤖 AI Document Generation: writing documentation sucks: it’s boring and repetitive and not the most valuable use of your or your client’s time. Can we use modern AI models to speed up the process of writing draft documentation?