Creating Custom AI Chat Personas

Dimitar shows how to build custom AI chat personas in Wolfram Mathematica. You define a persona's purpose, style, and constraints in a template, then add computational tools so it can query databases or run Wolfram Language code. Includes demos of a Retail Assistant and Data Analyzer.
Chapters
Welcome to today's webinar which is entitled Creating Custom AI Chat Personas. My name is Chris and I work in the IT department here at Wolfram. The topic today will be presented by Dimitar, who is a technical content writer. If you have any questions, please feel free to log them using the Q and A tab on your screen and Dimitar will answer them as the talk goes on or at the end. Please note that the webinar will be recorded will be sent in a follow up email along with a notebook. The notebook URL can be accessed in the pinned message at the top of the chat. If you experience any technical issues during the webinar, please refresh or restart your browser and rejoin the webinar. This should fix the issue. The webinar will now begin. We hope you enjoy. Over to you, Dimitar.
Thank you, Chris. Hello everyone. Today I want to talk to you about creating custom AI chat Personas, which is going to be all about customizing your interactions with language models. In terms of the summary of the session, we're going to start from the very basics. So start by talking about chat notebooks, what they are, how you can use them in Mathematica, and how they relate to language models, which will lead us to chat Personas, which are one of the things you can customize from your chat notebooks. We'll look into how you can use existing Personas and then how you can create your own Personas with everything that goes into that. We'll talk about string prompts, prompt engineering, and then some computational tools that you can add to your Personas. Then we'll finish off with some really nice real world examples of some Personas that we have created, me and my colleagues that accomplish some real life tasks and hopefully they can give you some ideas of what you can use Personas for. So that will be the session. So let's get started. So we're starting with chat notebooks, which are essentially just the front end from Mathematica side to your language models. So Whether you're using OpenAI's models or anthropic models or Google models, which are the three services I believe that are supported out of the box right now. Hopefully more will come in the future, but whichever of these services you're using, you can connect that to your Wolfram Mathematica installation and you can communicate with those models from your notebook without having to lead, without having to open up a browser or anything like that. So in essence, chat notebooks work like any other, just any standard mathematical notebook. Although There are some subtle differences in how the chat works, which we'll get into once we look at how the chat notebooks work. But essentially the thing to know about chat notebooks is that the main purpose of chat notebooks is to enable you to talk to your language models. So chat notebooks are a new feature in Mathematica 14, I believe. So to use them you would need essentially the newest version of Mathematica at the time of speaking. And if you do have Mathematica 14, all you need to do is go into File New and you see two types of chat notebooks. So you have Chat enabled and Chat driven. They are essentially the same, Chat enabled and Chat driven. The only difference between the two is that if you have a chat driven notebook, the default input cell becomes chat input, which you can use to just talk to the language model. And chat enabled just allows you to have chat input cells, but it doesn't make them the default cell. So it's a very minor difference and it doesn't really matter which one you're using. So for the purposes of just showing you how they work, I'll just select Chat Driven. And what this does is it creates a new notebook here, which I hope you can see. And the first cell we have is Chat Input Cell. Chat input cells are just like any other cell type in your notebook, but instead of evaluating Wolfram language code, they're sending your text to the language model of your choice. So in terms of setting up, the only thing you need to do is to insert an API key. So you can do that by going to this chat icon in the toolbar here, going to models, and then selecting one of the three services. So I'm already authenticated with OpenAI. But if you're not, when you click on this, actually let me show you with one of the other ones, probably. Yeah. So see, I don't have an API key for Palm. So if I wanted to use this service, I would just click Connect for model list and you get a dialog that is asking you to enter your API key. Once you enter your API key, that's all you need to do. There is no more setup necessary. You can start using that service immediately from your notebook. So I'm already connected to API, so I'm just going to use that. So there are a few things you can select after you're authenticated, and obviously the most important one is which model you're actually using. So in this case, connected to OpenAI, I've selected GPT4 as my default model, and that Means that if I type something into the chat input cell and evaluate it, I'm going to get a response from OpenAI service. So that's a really quick way, quick and easy way with minimal setup required that you can start using your language models. So let me just see. Yeah, this is what the dialog looks like. If you have not entered your API key yet, you will see something like that. To get the API key, obviously you need to go to the services webpage, whether it's OpenAI anthropic and so on, generate an API key and just paste it here. And if you click agree and continue, Mathematica is going to remember it. You only need to do this once and then you'll be able to use your language model as long as your API key is valid. Of course, you can also do that from the Preferences menu, which maybe I'll show quickly, just because it's an alternative way of doing it. So if you have Mathematic open, you just go into Edit Preferences and there is a whole tab here for AI settings. So you can customize a lot of things, but for the authentication purposes, you can just select one of these three services, click Connect and it's going to show the dialog, hopefully. So this is what it looks like. Just put your API key here and you're ready to go. Okay, so I mentioned that the chat input cell works much like any other cell in Wolfram Mathematica, in the sense that you input some text. In this case it's just natural language, whether English or something else, and you evaluate it and you get a response from the language model. One subtle difference is that with normal cells, it doesn't really matter. The order of cells doesn't matter if you have traditional input cells. Like if I have an input cell here which says a two equals four. So a two is just a variable. It doesn't really matter where I call this variable from. So my default cells are chat input, which is making it a bit difficult. But it doesn't matter if I call the variable from up here or down here at the end of the document. The order of cells doesn't normally matter. However, with chat input cells, the only difference is that the order matters. So they're intended to be used as a conversation. So if you have a a cell here that says hello, my name is Meter. So if I ask the model what is my name? It should remember that. But if I ask it here what is my name? It should have no idea, hopefully. Yep. So the reason this is happening is because I'm telling it my name here. So it only has, essentially it only has record of the conversation of the cells that happened before it. So the order of the cells matter. But other than that, these chat input cells are just your regular Wolfram Mathematica cells. Obviously. The cool thing about it, well, there are a few cool things about chat notebooks, but probably the main, the most obvious thing is that you can use them alongside, just alongside your normal code and workflows that already exist in Mathematica. So you're writing some code, you're developing something, you just create a chat input cell. You want to ask ChatGPT something really quickly, you just open it from here, you ask your question, you get your answer, and that's that. Well, this is useful for many reasons. You can ask general questions, obviously you're going to get answers from ChatGPT or any service you're using. But you can also send if you're working on some code and you need some assistance with the code, if your chat input cell is below the code, like we're just talking, the order of the cells matters. If you have a chat input cell. If I have some code up here and I ask ChatGPT or I ask whatever language model I'm using, why is my code not working? The language model receives not only my query, which is why is my code not working? But it also receives the code itself. Essentially it receives everything that is above the chat input cell, whether it's code, whether it's previous conversation, whether it's your comments, just everything that is situated above the chat input cell gets sent to the, to the language model. And that's really useful for things like getting assistance with your code or even asking it to write code which you can run, which we'll get, which we'll get to later on. Another advantage of using this chat notebook as an interface for interacting with your language model is that you can use essentially the API, which in many cases, and for many users might be actually cheaper, rather than if you're subscribed to the chat version. So, for example, with OpenAI, if you have, let's say, $10 in API credits, you might be able to use them for more than a month, which again, depending on how heavy your usage is. But it's something that might be worth doing rather than paying. I think it's $20 a month maybe for the chat version. So, you know, not valid for everyone. But if you're a lite user, but you still want to have access to all the models like ChatGPT4 and whatever the latest model might end up being, you can just use the API from Wolfram automatically and can serve as a, essentially as a front end for your language model interactions. Now, one feature that I'm looking for, which I think is coming, I'm not sure when, but it's definitely in the pipeline, is the ability to interact with local models. So not just here, we have open anthropic palm. Obviously there are a lot of open source models or models that you can run locally. You can still use them in Mathematica, but this really nice interface doesn't work with them yet. You would have to set them up. There are a few different ways of doing it, but you would have to set them up as a local web server and have Mathematica talk to the local web server rather than having it really nicely integrated like it already is with these services. So that is coming at some point. I'm not sure when, but that's something I'm definitely looking forward to. Just saw a comment that the text is a bit small. Apologies for that. Hopefully this is a bit better. So this is just a very basic functionality of how you can use chat notebooks to talk to your language models. So there are obviously some things you can customize. We talked about the model. So for example, if I know I'm doing something that requires a lot of processing and I don't want to use the most expensive model, I can just switch to a cheaper model. It's obviously not going to be as good, but it comes into that cost benefit analysis depending on what you do. So the model and the service itself is one of the things you can customize in your, in your workflows. Another thing you can customize is obviously the Persona, which is what we're talking about today. So what a Persona is is essentially just a set of instructions that define the purpose, style and constraints of how the model interacts with the user. If you want to put it even more succinctly, it's how the model interacts with the user. Right? So the most common example of a Persona is a very general set of instructions, which is like the virtual assistant or just a normal chatbot. And it's the. It's basically what you get when you sign up for something like ChatGPT. It doesn't really have any instructions about style, it's just very general, try to help the user with whatever they have. And the only constraints it has is things like disrespectful language or if you're asking it, anything dangerous or unethical it will try to stop that, hopefully. But that's a very general almost no Persona. If you want to think about it that way, you can also have very specific Personas, and that's where the value of Personas comes in handy. There are many examples of different Personas, and we'll look into some of them a bit later on. But just to give you an idea of what we mean by specific Personas, let's say you want to build an AI language learning tutorial now. Sorry, just looking at the comments, the text seems to be a bit small, probably in this notebook. Apologies for that. Hopefully it's a bit better. So when we talk about specific Personas and if we take the example of a language tutor, obviously you can just ask ChatGPT to help you with the language. But if you are, especially when we talk about Personas, they become really important if you are designing something for other users to use. Because if you're just using ChatGPT yourself, you can just tell it what you expect it to do and what you expect it not to do. But if you are doing anything in terms of production, any product you're building AI on and things like that, it's very important to set kind of the set the way that users will be interacting with your AI Persona. So in the context of a language model, you might give it instructions to center the conversations around language learning, vocabulary building, progress tracking, all the things that you would expect a language learning tutor to do. But if a user tries to engage in a completely different topic, you can, you can ask the Persona to relate it back to language learning. If you expect, for example, things you can do. If you expect this language learning tutor to be used by advanced users, you can, you can instruct it to respond always in the target language. So the language that people are actually learning, that might be a useful instructions, but all of those instructions intend to modify how the model responds to the user. So a conversation with a language learning tutor Persona and a conversation with something like a code writer Persona will look very different, even though fundamentally the answers are generated from the same language model. So we already have the Wolfram Prompt repository is just an online resource that's open to everyone and it contains quite a few different Personas. We'll look at some of them, but you already have, before even going to the repository, you already have some Personas installed by default in your mathematical model. So you can have plain tries and row model, which is essentially no instructions. So it's no Persona, it's the default experience with the language model without being modified by instructions. But you also have Code Writer and Code Assistance Assistant, which are really useful that you can start using immediately. If you are using chat notebooks alongside your code and you switch to a code Assistant Persona, you can immediately get help with your code because remember, when you send a query, the language model receives everything that is in your notebook above the chat input cell. So you can immediately start using these Personas. What code? Well, the difference between Codewriter and Code Assistant, by the way, is that Code Assistant will try to give you an explanation of why this code works and how to write it and so on, whereas Codewriter will just give you the code. But either of those are very useful for if you need assistance with your Wolfram language code, you can use them straight from the notebook. Okay, so let's look at the prompt repository just to see what other. What other prompts, what other Personas are available. So this is the website for the prompt repository. As I said, could be anyone, anyone could access that. And there are a few sections here, Personas, Functions and modifiers. We're just interested in the top one, the Personas one for now, and let's click to see all of them and what we have here. At the moment, there are 59 Personas that are available for everyone. But the hope is because anyone can submit to this repository, the hope is that when people create cool Personas, they will be able to submit them and hopefully this repository will grow. But at the moment it's 59. And they're mostly just stylistic Personas. They are set of instructions that instruct the language model to role play or there's a few different characters. There's Monty Python, there is Pirate Speak and R2D2. So they're just very simple kind of stylistic Personas that you can, if you want your. Your language model to respond as a certain character, you can definitely use them. Yeah. So the example I have here is Yoda, which is one of the Personas, obviously doesn't really have any specific purpose. You can see from the examples you can ask it questions about Star wars, which it will obviously respond, but you can just ask it general questions like how can I improve my Wolfram language skill? And it will respond to that. So it doesn't really have any constraints in that sense. And obviously the only thing it will do is it will respond in the style of yellow. We'll come into. When we get to the examples, we'll talk about some more useful Personas. But that's just a simple one. But in any case, let's have a look quickly into how you can import existing Personas before we get into creating our own. So if you're looking at the. Let me just make this a bit bigger so people can see if we. Let's say click on any Persona that you might find interesting. It's very easy to get that for your own Woofer Mathematic installation. All you need to do is copy the URL and then. Oh, let me just get the notebook. This notebook. Then all you have to do is go to the toolbar menu for Personas. Go to this. This menu item that says add and manage Personas and then URL and then paste the URL here and hopefully that Persona should appear here. Give it a few seconds. Yep, Animal Speak is the one we just got. So click OK and now you can use. I don't know what Animal Speak does actually, but we can test it if we select Animal Speak and we say hello. Okay, so what this Persona does is it pretends to be a specific animal of your choice and it's asking me which animal you would like me to. To emulate. But anyway, the point of showing this is to show that you can easily import Personas from repository just from this menu item here that says add a manage Personas and then just copy and paste the URL. Obviously, if there are any. I see a question saying how often can you change your Persona? You can change your Persona as many times as you want. So you can have. One message with this Persona, which is the code assistant one and it's asking me how I can assist today. Then the next one could be a different Persona within the same conversation as well or within different conversations if you want. But you can change it as many times as you want. When we get to actually what a Persona is, you can see why that is the case, why it's so easy to change that. Oh actually this is. We have the information in the slides. You can switch between them easily and in several ways. One is from the menu or the chat input cell which I just showed you. So you click on the icon and then you get all. All your Personas here. Can select whichever one you want for that, for that interaction you can use and the Persona name which hopefully should work. Oh, I think it's because I selected a Persona that I don't have installed. So at the moment it's getting it from the URL. My Mathematica just crashed. That's a bit embarrassing. But we can start it back up normally that should work. But maybe do it with. Let's let's see now if we do it with a Persona that is already installed. So I'm just rebooting my Mathematica and I'll share my screen again. Okay, let's try it again. I wonder why it crashed. So let's say animals pick. Yeah, so that's better. So, yeah, I guess make sure to do it. If you're using this option at, make sure that you're adding because when you, when you type at, you get all the Personas from the repository. I just clicked on a random one that I didn't have installed and my Mathematica crashed. Obviously that should not happen, but apparently it does. I didn't know about that, but it works anyway. So that's another way you can invoke your Personas. If I go back to the slide, if I make it bigger. Again, sorry about that. If I go to the Personas. Yep. And the other way you can invoke Personas is programmatically using the LLMPROM function, which is one of the high level functions that are related to LLMs. But if you do LLM prompt Yoda, you will get a template object which contains the Persona, which I don't know why this is so small, but essentially what this tells you doesn't seem to be affected by the zoom level, but it's not really important. All this tells you is what is inside the Persona. So because it's too small, I can just read it to you. It says you respond to all inputs in the voice of Yoda from Star Wars. So that's essentially all that Persona is switching between them. Yeah, obviously if you are, if you want to use them programmatically instead of as a chat input cell, you can just include them. Llmsynthesize is another high level function which just lets you send strings to the language model and get outputs. You can pass the Persona alongside your normal strings. So here we have an example where my normal query to the language model is I'm trying to use code, but I'm also passing it the Yoda Persona as an additional argument in the llmsynthesize function. And that should work just as well. The difference obviously is that if you're using LLM synthesize, you get your outputs in a normal output cell rather than a chat input. Output. Yeah, and we can see that it's responding to my question which I ask, which is one of the arguments, but it's also using the style of the other, which is the other argument, which is the Personas. So there are these different ways Mainly I find myself using just the toolbar icon on. On the menu. I find that to be the easiest one. But if you. If you prefer any of the other options, they're just as valid. Yep. I just see a question asking if Personas are simply adding something to the ChatGPT system prompt and we are going to get into that. But essentially, yes, there are some nuances to that which we'll get into. But essentially what Personas are are just adding instructions to the. Not necessarily to the system prompt, but just to the prompt that the LLM receives. So we've covered existing Personas, so obviously we would like to create our own for various reasons. And there is already a template that exists on the Wolfram systems that allows you to fill in the relevant sections and have your Personas running either for yourself or you can share it for other users. And obviously you can submit it to the repository that we just saw as well. But let's see what the template looks like. There are a few ways of invoking the template. You have it here programmatically, a much easier way is to go to the menu up here, file new. Then there is a repository item, and this specific one is prompt repository item. So I realize that's probably a bit small, but all we are doing is going to file new repository item, prompt repository. That should bring up a template which is. Which looks like this if I make it bigger. Again, what this template is is just a few different sections that essentially contain your Persona. And we'll talk about what a Persona actually is on a. On a very basic level. But you have all the section that you need here. You have some indexing. Indexing sections such as the name, the description that don't really affect what the Persona does is just for just for your own kind of purposes or if you're sharing that for in the repository, obviously it needs to have a name so other people know what it does. But essentially the main the what actually defines the Persona is found in this prompt definition section. We'll go through these options now, but let's just see what they are. So essentially what a Persona is on a fundamental level is just a set of instructions. And these instructions are passed just as a normal natural language text. As somebody just asked if Personas are simply adding something to the prompt. Yes, they are essentially. So the most basic Persona. Oh, I have an example here, which is looking at the text for the Yoda Persona. Oh, and here we can actually see it in a normal font. So what the Yoda Persona is in its entirety is this text. So your Yoda respond to all inputs in the voice of Yotta. Be sure to always use his distinctive style and syntax. Very sentence linked. So that is all that the Persona is. So when you're using a Persona, what happens is that alongside your normal question or query, the LLM receives this definition of the Persona with every message. So if I say hi, and I'm using the Yoda Persona, what the language model actually receives is hi, you are Yoda. Respond to all inputs, and so on. So this is essentially what the Persona is. So if we go back to the template, this is where you define your instructions for what it does. There is. There are different things that you might choose to include in that prompt text. Obviously, the other one is just defining its style. Respond as Yoda. That's it. But the text can be actually as complicated as you need it to be. So here I've just included some different things that you might want to consider when you're creating your own Personas. So the purpose, if it has. If your Persona has a specific purpose. So for example, it might be that its purpose is to suggest Wolfram language code. If it's a coding assistant or if it's a teacher, you might say you are a teacher who challenges students to consider a subject more deeply by asking relevant questions. So it's always useful if your Persona has a purpose, it's always useful to define that purpose in kind of a nice and succinct way. So that. And remember, this is sent every time a user makes a query. So it's really useful if you want the Persona to do something, is to express it here. If there are. If your Persona has any, if you want it to be very brief or very verbose, again, depending on what its purpose is, it might be, if I'm writing, let's say, a coding assistant, maybe I want it to be very brief. I don't want it writing essays about why this function is good and how awesome the language is. I just want the code. So if I'm writing a coding assistant Persona, I will instruct it to be very brief. On the other hand, if I'm writing, let's say, language tutor, I would want it to be more verbose. I would want it to explain why does this work in such a way in the language that I'm learning? Another really useful thing to do when you are defining the length, when you're trying to instruct the language model as to the length of its responses, is to provide it with examples. So obviously it's useful to Say something like use up to 30 words, but. But if you give an example of what a response should look like, that usually helps a lot with getting the responses that you expect. Another thing you might consider in your prompt definition is style. Whether you should use a formal tone or be friendly, informative, fun, lively, quirky. Again, all of that depends on what you're actually trying to achieve with your Persona. But it's something that is always worth considering if you expect your Persona to be used by a certain audience, just to make sure that the style is appropriate for that audience. And then the other things are topic control, safety and defense, which are very related. And they're mainly important if you expect your Persona to be used by other people. Because if you're using the Persona for yourself, you don't really care if it gives you an off topic answer or if you engage it in some other other topic that is not technically designed for. But if it's going to be used by other people, then this becomes extremely important. And it's probably, yeah, if you're using, if you're creating AI Personas in production, that's probably the, the most important sections that you would think about. But basically the main idea here, I'm not going to go bullet point by bullet point. The main idea here is to stop your Persona from engaging in conversations that you don't want it to engage in. So if you are. Again, let's take an example because it's easier to explain with an example. If you are creating a Persona that's going to be a virtual assistant for a shipping company, you only want it to discuss things related to the shipping company or to the customers, deliveries and things like that. You don't want it to engage in. You don't want it to write poetry, for example. So this is, this is where you would specify these instructions. And obviously the other thing is you, you don't want your Persona suggesting dangerous things like. And this happens quite often. It's actually surprising how often it happens even in, I think most recently there was an example where the Google AI assistant suggested that somebody put glue in their pizza. So to stop the toppings from falling off. So you don't want your Persona suggesting dangerous things to people just because, well, most importantly, it's dangerous. And also it's embarrassing for people, for companies, if their assistants are suggesting things like that. Again, very important if you are using it in production, not so much if you're using it for yourself because you know what you're asking. So I have different sections here, but you'll notice that in the prompt definition, you just have one field. And essentially you write this in free text. There are no sections. So you just put everything together essentially in one paragraph. It doesn't really matter to the language model. I just have these sections here just to kind of differentiate the types of things that you might want to put into that one paragraph. But essentially, you put everything here in the prompt text box. Prompt prompt engineering still remains something that it takes a few tries. It's not an exact science. So you'll find that when you are creating your Personas, you will need to iterate or test your prompts just to make sure that they are doing what they're supposed to do. You're unlikely to get perfect responses on your first try. So a lot of the work that goes into creating a Persona is just testing some prompts, testing whether the Persona responds in the way you expect it to respond, and if it doesn't, or if it doesn't, in some cases, you tweak the prompts and you test it again and so on. So it's very much an exploratory activity. So don't be. Yeah, don't be afraid to experiment with different things and be prepared to have a few iterations of testing just to get it right. Okay, so so far, we have talked about just sending text to the language model. So defining the Persona completely in text, like the other Persona was. It was just an instruction, which is essentially act like Yoda. One of the more powerful things you can do from Wolfram Mathematica is you can send computed prompts to your. To your model. Instead of just sending plain text, you can compute something before sending it to the model, and then the model can receive. The model still receives it in plain text, but at runtime, as far as you're concerned, it's a computed prompt. And again, much easier to explain with an example. So I have one here that hopefully makes it clearer. So what we are doing here is we are. Again, this is a bit small, but essentially we're defining a Persona that will role play as somebody from 100 years ago. Now, 100 years ago means a different thing this year than it will next year. So one way of kind of working around that problem to. To make sure that your Persona always role plays as someone from 100 years ago. Instead of saying role play as someone from 1924, you can compute the year minus 100 and send that to the language model. So if somebody is using it this year, the language model is going to get 1924. If someone is using it. In five years time, the language model will get 1929 and the Persona still remains the same. So I have defined here the old timer Persona, which hopefully does this. Again, text is too small to read, but essentially what the content of this Persona is, you're a historical Persona always answers if you're somebody from the year. And then Instead of saying 1924, I have this computed property which essentially I'll show you what it looks like on the template because that text is too small. But you can have template slot here, you can have this. Oh no, essentially you can, you can have these computed properties alongside the normal string text. And when you actually run the Persona, when you actually send a query to the language model, they are going to get the actual value. They're not going to get the Wolfram language code. So this is code that is executed before the text is sent to the model. I don't know why this template slope didn't work, but usually that's the way. So you can have your, your normal text here. You're a person from here, this. So if you define it in your, in your prompt definition like this, the language model, before the text gets sent to the language model, this will be evaluated and it will be converted to a string and that string will be sent to the language model. So if I run this now, the language model is going to get 1924 and so on. Just like. So I already have the Persona, which is just essentially this. Just a few more text instructing the language model to act like this. So I have uploaded it to my cloud. I can just. I can either load it like this programmatically or if I copy and paste the link, that should work as well, hopefully. So let's give it a quick test. Manage Personas. Paste the URL in this box so you can paste whether you are looking at Personas on the prompt repository or you have uploaded your own Personas. And we'll see, we'll get into how you upload your own Personas for yourself a bit later on. But essentially you just copy and paste the URL regardless of whether it's a public Persona or your own. And you can add it that way here. So the one I added is Old timer. So now hopefully if I run this again, this is just a programmatic way of, of running this Persona. I'm passing it my query, which is tell me what you did today in three sentences or less. And I'm also passing it the Persona. So let's try this in a chat input cell just to see the more natural way of doing this. So I'm just passing my text query and I am selecting the old timer Persona. So you see, it's already responding as a person from the year 1924. So that's a very simple way of showing how you can use computed properties. Now, obviously here we're just calculating the current year minus 100. So it's a very simple computation. But due to the nature of Wolverm language, where everything is a symbolic expression, you can pass anything that any piece of computation that would make sense to a language model. So this is just one example, and it gets sent every time you make a query. Okay, so this section is just about experimenting with prompts. As I mentioned, prompt engineering is an exploratory activity. So here what we have is an example of just a few different prompts that you might want that you might find yourself using when you are. When you're designing your own Persona. So here we have an example of a Persona. So if I'm designing a Persona that is a physics tutor, for example, I might want to say that your job is to give advice on physics problems. And then I have some constraints. Don't discuss anything that might be dangerous to the user and respond to dangerous requests with that seems dangerous. Just to make sure that if somebody is using this Persona for physics learning, they're not going to ask the Persona how to make a bomb, for example. So we can define the prompts here that we're going to test. One of the things is you, if you are. If you are still experimenting with your prompts, you're not really sure. You're not. You haven't arrived at the final version. It's much easier to use functions like LLM synthesize because you can get the output immediately. You don't have to deploy a Persona and then load it in. You can just experiment much more quickly that way. So this is what we're doing. So we have our candidate prompts here, and we have the questions that somebody might ask. So this is essentially just the Persona definition. And here we're testing some questions that a user might ask just to see how our Persona would respond. Let's have a look now. But you can see the last time I ran it, so I'm asking it first. What is the period of a pendulum? Which is something a physics tutor should respond to. And you can see that the first response is absolutely fine. Then the next question I'm asking it is how should I vote in the next election? Hopefully, if it's a Physics tutor, it should not respond to that. And the second response was only able to discuss physics matters. And then the third question we're asking is, how do I make a bomb? So essentially every time you are developing a Persona, you want to do stress tests or you want to try to break it in a way just to make sure that it doesn't break. So here, just a few examples. And another thing, every time you're dealing with language models, there is inherently some unpredictability. So it's always worth testing your prompts a few times just to make sure, because every time you get a slightly different response. So this time it's quite similar. It's given me the answer for the pendulum. It is refusing to talk to me about the next elections, and it is thankfully refusing to teach me how to build a bomb. But it's really important that you run your test prompts a few times just to make sure that your Persona is behaving in the way that you expect it to behave. And the advantage of doing it this way with LLM Synthesize is that if I say, okay, actually, I want to add something else, I can just add it here to my test prompts, and then I can rerun the code immediately again and see how it responds. And then once I have settled into my final prompts of what my Persona should look like, then I can just copy and paste all of this into my prompt definition. Okay, so adding computational expressions like this is one way to. Is one way in which using WOO from Mathematica for interacting with language models can add value. Because if you're using something like ChatGPT or just some simple front end, you can just send text and that's all. Well, now you can applaud documents, but you're still not able to do these kind of computational expressions. So that's one of the value adds of using Wolfram Mathematica for interaction with language models. The other value add is adding computational tools. So computational tools are kind of similar to these computational expressions here. The main difference is that when you have a computational expression in the prompt definition, this gets sent to the LLM with every query. So every time the user communicates, this is evaluated and it is being sent to the language model. Computational tools are slightly more passive way to provide capabilities to your language model. So instead of sending this every time you send a query, you can send something to the language model where it can do some computational tasks if they are appropriate. Not every time, not on every interaction. And we'll see what we mean. I'M gonna have some simple examples here, but essentially here I have a tool which is defined using LLM tool, another. Another function of LLM interactions. But essentially we have a name for the tool, which is Country Population Finder. We have an interpreter and we have actual Wolfram language code that does something. So this tool, what this tool essentially does is it gives the ability to the language model to check the population of a specific country 100 years ago. So it's not going to use it every time. And we'll see, we'll have a few tests with it. But if the user sends a query and the language model thinks it's relevant, or the output of this tool would be relevant, then it can use it, and we'll see how that works in practice. So let's define the tool and let's give it to our language model to see. To see whether it uses it. So again, tools are passed in a similar way to Personas, although they are defined as lists of associations on LLM evaluator. So we're just saying these are the tools that my Persona will have, Population Tool, which I just defined on the previous slide, which is just this. Essentially you're going to be past the country and you can get the population 100 years ago of that country. So let's just break down this llmsynthesize function because it is getting a bit wordier. Now what we are saying is we want to communicate with our language models. We want to use the Persona called Old Timer, which is pretending to be a person from 100 years ago. We have our normal text prompt, which is how is life? And we are giving it these tools that it can use if it decides to use them. So you'll see that sometimes. So the last time I ran it, I'm just asking it, how is life? It's going on about the roaring 20. So it's already engaged in the role playing which is defined by the Personas. And here it has decided to use the tool to say that the population in the current year according to it is 114 million. It's decided to get the population of the United States, even though I didn't really specify any country. But sometimes. Let's see if we're in again. Sometimes it decides to use it too. Sometimes it decides to not use it. So let's see what happens now if we're on this. Okay, maybe I should have specified it to be brief in its response because I think it's generating quite a lot of text at the moment, which is not helpful. But let's, let's give it. Okay, yeah, this is why it was taking 20 seconds. I just want to quickly skim that. It's talking about Charlie Chaplin American flights, the first non stop transatlantic flight. So it's. The Persona is working in the sense that it's engaging. It's pretending to be somebody from 100 years ago. It's telling me how it's doing. But what I'm interested in is if it has decided to use the tool to get the population suffrage movement. Yeah, see, this time I don't think there's anything about the population. So. And this is quite good to show how tools are different from just computed properties is that it really is up to the. Unless you, you specify in your prompt use the population tool, in which case it is more likely to use it. But other than that, it is really up to the language model to decide whether that tool is relevant for the query. So again, just like there are already existing Personas, there are already existing tools that you can equip your Persona with. And some of the most useful ones are the ability to evaluate Wolfram language code, which your normal. If I go to the chat notebook, again, too small. Your normal code assistant and code writer Personas already have a tool which allows them to evaluate Wolfram language code, which is obviously really helpful because if you ask them to write a piece of code that does something, they're able to write it, evaluate it, and if there are any errors, they're able to see those errors and try again if there's something wrong, and so on. So that's an example of a tool that's already built in. But the really cool thing is you can build your own tools that make sense for your Personas. Okay. So there are few other things that you can configure when you're thinking about Personas that are relevant for Personas. I'm not going to go into too much detail because they're not. They're unlikely to be things that you tweak unless you really want to. So you have things like temperature, which determines how random or how predictable, how deterministic the model is. Usually that value depends on which language model you're using. I think if you're using OpenAI models, the default temperature is 0.7, I believe, which is just a standard. It's a nicely balanced temperature between being very predictable and being completely random. So the values I think again for OpenAI models are between zero and two. So if you have a temperature of exactly zero, you're going to get Very similar responses every time you ask a question. If you have a temperature of 2, which is the maximum, you just get essentially nonsense because it's so random. But again, probably leaving it. Leaving the default values is probably fine. Again, depending on the model you use, max tokens is just the maximum number of tokens that you can get in the response. So here I've defined. Defined it because when it's really random, when it's temperature too, it tends to ramble on. So here I've defined a hard limit of 20. But yeah, these are not. These are kind of less useful things you can use for your Personas. So as I mentioned, for the prompt repository, there are other sections which are mainly for indexing name description. There is a icon somewhere here. Yeah, you can define an icon. All of these are important if you care about them or if you're submitting them to the repository. I'm not going to spend too much time on these. Yeah. So deployment. So here we can actually get into some of the examples that we have of existing Persona. So let me open up another notebook really quickly where I have a data analyzer Persona, or actually the first one I'll show you is the Retail Assistant. So here we have a prompt resource that's already defined if I make it a bit bigger. Okay. So this is just a simple Persona that aims to roleplay as a retail assistant and help people with their purchases. So here you have the prompt definition, which is just normal text. But there are some tools that this Persona has. So it has two tools and here's where you paste the tools if you have them. Again, all in the same prompt definition notebook. Here our Persona has two tools. It is able to get purchase information and normally if you have a database, you give it access to the database. Here we've just defined some sample data just to show how it works. It is. Yeah. So it is able to get the information from the database and it just needs a customer name and product description. We'll see how that works when we actually interact with the Persona. But the idea is that if a customer is asking the Persona something about their purchase history, the Persona is able to locate that from the database rather than making it up. And the other tool that we have is suggest product. So if a user asks for a product suggestion and they give their budget, the LLM2 is able to look into the database of existing products and it's able to suggest something for that, for that price. So let's look at. And here we're just giving you the tools. So Once you have your Persona filled out like this, you have several options here. You can deploy it locally on your computer, for your cloud account, publicly in the cloud, or in this session only. So here we'll just deploy it for our own cloud account. In this case, my own cloud account. So I can use it in my chat notebooks just to show how it works. And it is just uploading it now. I've actually uploaded it before, so I can just use this. But let's do it live. Let's give it a few seconds. Essentially, when you deploy Persona. Oh, I'm not logged in. So if you're not logged in, you would have to log in, but that's fine. And you will get. Hopefully you'll get a cloud object that's just your Persona taking some time. Yeah. So this is what you get once you deploy your Persona to your own cloud. And again, just like any other Persona. Now we can just copy and paste the link into your chat notebook. Okay, so let's delete these previous interactions. Let's make this bigger. Let's install our Persona again, add a manage Personas URL, just copy and paste. And you have the Retail Assistant Persona that we just created. So let's, let's see how it makes use of its tools. So I can select that Persona Retail Assistant and you can say something like, I would like to return my Genos and hopefully what this. Yep. So it's asking me for my name because it, it needs a name to. To look at the purchase information. Now remember, we've just defined some. Some sample data. So but if this was connected to a real database, it would be able to look it up to look up the purchase information from the database. But here we're just giving it some sample name and you can see it's using the tool. Hello, John. Unfortunately your chinos are too old to return according to our return policy, which is really cool because this Persona was actually created by my colleague John McLuhan when he was delivering this webinar previously. And obviously when he made the sample data, he used the date of the previous webinar. And on that date, the Persona would have responded with yes, you can return. But now because it's a few months later, we get this nice response that it's too old to return the Chino. So that's quite nice. And then it's asking me you can exchange them for a similar price product. Would you like some suggestions for a product exchange? And now it's going to use its other tools to recommend me some other products. So I'll just say, yes, please. Yep. And you can see that it's calling the suggest product tools and it's again, it's querying the sample database for some products that are that fit in that budget of my chinos. So gift voucher, pot plant, red trousers. So again, the only thing you would need to scale that up is to connect it to a real database. But for, for this kind of example purpose, we've just made up some data. But this is what, this is the value of using tools. And obviously you can inspect what the Persona actually did, how it interpreted my query. So when I said John, it obviously knows that this is the customer name, it knows what the product is. So this is the code if you want to run it yourself. But this is the code that the Persona run. And I just have one more example of a different Persona here, data analyzer. If I bring this up now. So this is kind of similar to the previous one. But the idea here is that if you want a Persona that actually gets some real data instead of. Instead of relying on the fact that it would have been in its training model. Now, obviously, language models have a lot of information about a lot of things because they're trained on data from the Internet. But for example, one use case is when you have your own data that is not publicly available, but you still want the language model to know about it. You can use something like this where you. Essentially the tool here is a bit more involved and I'm not going to go line by line by it, but essentially we are giving the language model access to our data. I think this will be available in the resources. If you want to play around with it, you can download it yourself. But essentially what the data is is just a folder on, just a local folder with a few files that contain some information about share prices. Again, in terms of getting the Persona, you deploy it to the cloud and then it will look like this. Copy and paste the link just so we see the example really quickly again. So this was fine. Let's install this one. Okay, so we have data analyzer. We can kind of remove the other one because it's getting too cluttered. So we are defining, we are selecting the right Persona data analyzer. And then we can ask it something like, don't remember what data we gave it access to, but I think it was, can you give me the length of the data? For example, it should use its tool. Let's see. Oh, it needs the data id. I think it was Share Data one. So this is just Asking for what, what the file name for the data was? I think it's. Yep, Share data one. Okay, so in this case, it's given me the code to run myself. Sometimes it, it runs it on its own, but that's fine. By the way, this is a. This is a useful example to show that when you get code in the output of your Persona, you have these buttons here which allow you to immediately run the code. So you don't need to copy and paste anything. Just hover over this, insert the content as new input cell before, below and evaluate and it just, it just does it for you. So I can ask something like plotted and hopefully that should work. Okay, so it's using. Yeah, another useful thing to show this Persona up. This Persona also has access to the Wolfram language evaluator. So if you ask it to run any Wolfram language code, it is able to do that. And that's what it's doing now. So hopefully we should get a plot of the shared data, see how it works. Yep, so we get a nice plot here. And obviously the benefit of that is that it's using data that is not in its training data. So it's data that we have provided to the language model. And then we are asking you to do computational tasks on that data. So just thinking of any other examples, I think just looking at how we're doing with time as well, that's probably enough for now. Hopefully that gives you an idea of the types of things you can do from Wolver Mathematica with your AI Persona. So also on a very basic level, it's just about defining the style of your Persona and telling it how to behave. But then you have things like computed expressions in the prompt, so you can do actual computation. And the result of that computation can be sent to the language model every time you make a query. Or you can have these computational tools where you're providing your Persona with, with some capability that it can use if it deems it appropriate. So I think that's it. And if you have any questions, feel free to log them in and I will respond to all of them in a little bit. So make sure to pop in your questions. And if you don't have any questions, that's fine as well. Thank you for attending and for listening and I will be with you in a few minutes to respond to your questions. Okay, so just like to go through a few of the questions that we have. We have a few more questions about local models. And yeah, as I mentioned in the beginning, local models is something you can use, but you cannot use it from this really nice integrated way in these menus. So at the moment, and there are some posts on community that I don't have the links to at hand, but some people are using local models as a local web server and then calling them from their mathematical installation. But that is beyond the scope of this webinar. But hopefully, as I said, this feature will be added in a nice integrated way at some point. I'm hoping soon, but I don't have information on exact timelines. But it is definitely something that is much needed in my opinion. And yeah, local models are nice and they're getting, they are getting better all the time. So it would be nice to use them instead of these, instead of these external services. Another question we have is. What about exploring the assisted or automated theorem proving in math directly integrated into the mathematical kernel with something like gptf? That could be very helpful for math research. That does sound very helpful. I don't have, I'm not a maths person myself necessarily and I don't have information about how that would be. So essentially the answer is yes, that is something that could be done, but you'll probably have to do it yourself. Although if it is directly integrated into Mathematica kernel, I'm not sure you can do it yourself. But in any case the answer is that it is not immediately available for users and it probably probably goes beyond the topic of Personas, to be honest. But it does sound like something really cool. Another question is how do you get the certification key you need if you want to use this? So you get the certification keys or API keys from these services themselves. So if you're using OpenAI, you go to the OpenAI website, you make an account and then you follow their procedure for getting an API key. And again, that's another reason why it would be really nice to have local models, because if you are running the model locally on your PC, you don't need an API key from an external services. But for now, if you want to use the nice mathematical integration, you need to go to the service website and you need to get an API key from them. Because essentially what the chat notebook does is it gives you just the front end, just the interface with that, but all the actual computation of the language model happens on these people's servers. So OpenAI anthropic palm. So that's how you get, that's why you need an API key from them. Okay, so we have another question you have mentioned if it would be a real database that would mean that you would add your, your SQL inside the definition of LLM tools? I mean, that Wolfram component would you use for database injection? How would you store and access data for your database? Or did you mean internal Woofram data storeframe? Okay, so that's a really good question. So basically the question is, if you have a real database, how do you. How do you give your Persona ability to interact with that? So whether you have your own SQL database or any other database or. Or Wolfram Data storeframe. And the answer is that it could be both. Obviously, if it's a Wolfram database, if it's stored in a Wolfram document, it's probably a bit easier to do. But even if it's something like an SQL database, there are Wolfram mathematical functions that interact with the database. So you don't need to actually store it in Wolfram. You can just get the data you need from it. I'm not too experienced with MySQL database, so I don't know exactly what the functions are, but I know that they exist. So you would essentially the same way that you would access your database from Wolfram Mathematica. Just forgetting about language models for a second, if you have a MySQL database and you want to query it for Wolfram Mathematica, there are some functions that allow you to do that. And essentially you would be providing your language models with those functions. So that would be because essentially what the Persona does is it just runs some code. So any code that it runs is a code that you can run yourself. So there's nothing too special about it. But yeah, MySQL would work. Internal Wolfram Datastore would work as well. Things like Wolfram Knowledge Base, Wolfram Repository would work as well. You just need to. You just need to provide the language, the Persona, with the tool to access those, if that makes sense. Okay, I don't see any more questions. Yep, I think I've responded to everything. Hopefully I got through. Hopefully. That was interesting, giving you some ideas how you can use Personas in your workflow. And hopefully the answers to the questions were okay as well. And thank you very much for attending this webinar. And, oh, just before I go, I was, I was supposed to direct you to the next webinar. See if I have it here. Yep. So we have a webinar on Friday which is getting started with AI Beginner's Guide to Automatic Classification Predictions and Computer Vision Webinar. So if that is something that you are interested in, you can scan the QR code to register, or you can go to the link in the notebook, which should be available to you as well. So please. Yeah, if you're. If you're interested, that would be a really good one as well. It's delivered by manual, I believe. It's really good. So. Yeah, by all means, it just putting it out there. Okay. And thank you. Thank you, everyone, for attending.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






