If I could spend a day with any person on Earth, I’d pick Mark Cuban.
He sold his company for $6B, won an NBA championship, and became an investor on Shark Tank. There's just so much stuff I'd want to ask him about. The problem is — I don't know Mark, and I'll probably never meet him.
So instead — I did the next best thing. I used GPT-3 to make a group chat with Mark Cuban + a bunch of other people I look up to like Sam Altman, Steve Jobs, and Naval.
Here’s me asking the group chat what I should to do raise money for my startup:
Try it yourself @ Advisors.lol
Building this was pretty simple, and I'm gonna show you how I did it.
Let's get to shipping >:)
The first step is to make an account on Replit. It's an in-browser IDE. With Replit, we won't waste any time setting up a dev environment. Click the “Start creating” button to make an account.
After making an account, click "+ Create" in the top left corner, and select "Python" in the template drop down. Then click the " + Create Repl" button.
Nice! Now you have a main.py file. This is where your dream group chat is gonna live. To see if everything's working, write: print(’gtfol’) in main.py and click the big green "Run" button at the top. This logs your message to the console.
Next, you're gonna need an API key from OpenAI. Hit this link and login, or sign up if you haven't already. Then click your profile picture in the top right and select "View API Keys". Click "+ Create new secret key". Copy paste this key somewhere safe. We're gonna need it later!
Next, go back to your main.py file and write the following lines:
import numpy as np
Here we're importing NumPy and renaming it to "np". NumPy basically makes doing math stuff with Python really easy. Next, we're importing the OpenAI Python library. Finally, we're importing Jellyfish so we can determine how similar two strings of text are. This will be important later!
Finally, declare a variable for your OpenAI API key like this:
openai.api_key = <Your API key goes here>
Our goal is to make a text convo where you ask questions and some famous people give you answers. It's like a board of advisors, made with AI.
First, we're gonna create a list of "speakers" to keep track of everyone in the group chat. Then we're gonna make another list called "convo" to keep track of all the messages.
Go ahead and define your question, speaker, and convo variables.
Now let's define a function called board_of_advisors
Lots of stuff happening here. Try to understand the code before moving on. Here is a link to a repl with all the code
This function takes a list of people as an argument. In this case, successful founders. Then it uses OpenAI completions to generate responses from those people. The generated responses are based on the question variable we set earlier.
We created the variable
name that randomly selects one of the names from the list. If the name was used in one of the last three messages, it keeps searching finds one that has not been used yet.
Then we summarize the conversation by joining the elements inside
convo with a space. We pass this string as the prompt to the OpenAI API's
Next, we create a prompt for the next message in the conversation using the name and the summary. This will return the next message in the conversation as a response.
Finally, we format the response by replacing the double quotes with an empty string. Then we print the name of the speaker and the response. Remember to return the response in the function.
Now we need to define one more function. Lets called it
Same rules apply. Try to understand the code before moving on! You’ll get way more out of this note by being thorough :)
replies generates a conversation between those people we set earlier. The variable
question is the starting point of the conversation.
The function iterates
num times. Each time, it calls
board_of_advisors to generate a response from one of the people in the list.
jellyfish.jaro_distance(question, response) calculates the similarity between the
question and the generated
response. If it's less than 0.7, the response is added to the
convo list, and
question is updated to be equal to the
response. This way, the next iteration of the loop can continue the conversation.
If the similarity is greater than or equal to 0.7, the loop breaks, and the function terminates. The
convo list will contain the entire text conversation up to the point where the loop broke.
Final step! Write a function called
run and call it like so:
You can get your response using the following:
All this does is start the conversation we want to have in our group chat. It takes
number_of_messages as an argument for the # of messages that can be exchanged.
numpy to randomly select messages from the range given by
number_of_messages. This number is stored in the
Next, the function calls the
replies function with
num as an argument.
That’s it! If you click the green “Run” button at the top — you should see a live conversation in the console. Pretty cool :)
Try changing the value of the
question variable we set in the beginning. Here’s me asking the group chat what I should do when my startup isn’t going well.
The possibilities are truly endless here. I hope you take this code and add to it to make it even cooler! Hope you had fun, learned a bit, and had some sick convos!
shoutout to Alex, Praneet, and Omar for helping build this over the weekend.
— Arib and Mo
Join the the world's best builders for a 6-week sprint
Come join the best builders from around the world to build wild ideas in web3, ML/AI, gaming, bio-anything. You've got what it takes - all you need to do is apply