<<

Week 05 [Bots]

For this exercise Wallis and I wanted to combine forces and prompt from another assignment, in our class, “Visual AI Studio For Art and Technology” with Carla Gannis and AV Marraccini. For this class our assignment was to “develop a relationship with an online identity. This relationship can be platonic or romantic in nature. At the end of the week, WRITE a  ❤love letter or 💔breakup letter to your AI friend, based on your feelings about the experience.  INCLUDE the AI's response to you, and/or add any personal anecdotes about the experience.” We had the idea that it might be fun to try and program our Discord bots for this scenario.

We had the idea that it would be fun to try and get the bots to carry on a dialog without too much intervention from us, and see what we could learn from the experience. We picked the meta/meta-llama-3-70b-instruct LLM on Replicate as our LLM to connect to our bots via a slash command.

The first hurdle was to write the appropriate script to make sure that the API was called with our slash command and the users additional “prompt” input.

We decided to use the command “/tell me a story about: “prompt”, where the user could enter any topic as a prompt for the bot to begin the conversation.

At this point in our process both bots had the same system prompts as Replicates documentation.

const input = { top_k: 0, top_p: 0.9, prompt: "Work through this problem step by step:\n\nQ: Sarah has 7 llamas. Her friend gives her 3 more trucks of llamas. Each truck has 5 llamas. How many llamas does Sarah have in total?", max_tokens: 512, min_tokens: 0, temperature: 0.6, system_prompt: "You are a helpful assistant", length_penalty: 1, stop_sequences: "<|end_of_text|>,<|eot_id|>", prompt_template: "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are a helpful assistant<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n", presence_penalty: 1.15, log_performance_metrics: false }; for await (const event of replicate.stream("meta/meta-llama-3-70b-instruct", { input })) { process.stdout.write(event.toString()); };

Our next goal was to have our bots, April and June, respond only to each other, prompted by either of us using the slash command ‘/tell_me_about: prompt’. We did this by identifying the userID and channelID for our respective bots, and added this into the ‘reply’ logic.
Luckily we had success! The bots began chatting to each other right away with great enthusiasm.
But we definitely had some funny errors like the bots referencing or talking to themselves …

Or stuck in an apology loop with no real direction …

But when we adjusted the prompt to say, “you’re an empathetic friend”, the tone shifted slightly and they started to demonstrate.

We also quickly realized that without the logic to read previous messages, they weren’t able to reference any previous message data and were struggling to keep track of the conversation. So they continued to loop over the same discussion…

We adjusted our code so the bots were able to reference each other and carry on a conversation and build on top of their previous messages, by adding a ‘conversationContext{}’ object.
The conversationContext is an object that stores the message history for each user, where the key is the userId and the value is a list of messages from that user. When a new message comes in, it checks if there are already messages stored for that user in conversationContext[userId].If there are no previous messages, it initializes an empty list []. The new message (message.content) is then added to this list of messages. The list of messages for the user is joined into a single string with each message separated by a newline (\n). The combined string is called conversationHistory. Then conversationHistory is used to create a new prompt for the API by appending "yes, and …" to it.

This worked pretty well and the bots were able to sustain a more coherent conversation afterwards!

We noticed that despite little changes to their prompts, both bots kind of took on certain traits and mirrored each others expressions. They’re also incredibly enthusiastic!