Chatbot with INFINITE MEMORY using OpenAI & Pinecone - GPT-3, Embeddings, ADA, Vector DB, Semantic

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right guys this is really exciting so today's video is sponsored by Pinecone and if you know me you know that I have been like super resistant to sponsorships but when Pinecone reached out I was like yes this makes sense because I was going to use Pinecone anyways let's do it so what are we doing today first need to do a little bit of Preamble so um come and support me on patreon I'm almost at my goals at which point I will uh take down all ads forever um I might continue with sponsorships but that's fine so anyways my patreon is patreon.com daveshapp also if you sign up for higher tier you get to interact with me directly so that has less to do with the videos and more to do with just like hey if you have a question I'm happy to answer um Okay so moving right along a lot of you also know that I'm working on an open source AGI project or what I call artificial cognitive entity because artificial general intelligence is a useless term I actually prefer artificial Global intelligence because that's really the goal um you know like let's do Ultron but safe um and so the architecture the underpinning architecture for my project is what I call Mirage microservices architecture for Robotics and artificial general intelligence so uh the primary thing that you need to know about moragi is that it is all organized around a Nexus this is not a this is not a covid virus by the way um it kind of looks like one all right so the Nexus is uh as the name implies the center of it it is a hub and spoke model which means it is a very simple model now what is the Nexus the Nexus is primarily an information store a database now you could use SQL in my original experiments I actually use sqlite sqlite works perfectly fine um it is indexable however you're limited to SQL searches you're not you don't have good semantic search so we need to upgrade to something that does have semantic search enter Pinecone if you're not familiar with Pinecone we're going to go through from the beginning because I even though I've intended to use Pinecone for more than a year now I hadn't gotten around to it so now I'm going to get around to it so we're going to learn Pinecone together oh you know what I just noticed oh my OCD is going to kill me do you see this one right here one of the spokes is bent okay anyways all right so this is this is the highest level overview functional diagram for meragi is where basically you have a Nexus which is this is the data and the reason that I that I that that moragi is a data first or data Centric model is because I realize that all learning all experiences all knowledge are all data right everything that makes us human everything that makes us intelligent is about the information we carry and that we can then um reuse so information first it is also um it's a it's a data first model so that's that's kind of like the bits and bytes it's also a cognition first model and so what I mean by cognition first is Um this can think even without being connected to the outside world in any way it doesn't need sensor input it doesn't need motor output it can but it is a it is a cognition first and data first model of artificial intelligence okay if you're lost that's fine um scrolling down a little bit this is uh this is my Raven project so github.com Dave chap slash Raven if you want to get involved so basically there's a few layers of abstraction here let me make sure I'm not talking too loud okay cool there's a few layers of abstraction um to think about artificial cognition so at the very Foundation is data data first um so this is episodic and declarative memory which oh by the way a vector database is the optimal thing to store this in now that being said if you combine Vector search or semantic search with things like Knowledge Graph that could be even better we're figuring this out this is a large open source project it's about three weeks old and we're getting organized we're getting funding we're having talks about funding so on and so forth but the architecture is here oh man you know what I just realized there's an uneven Gap here too my OCD is just like way turned up today maybe it's all the coffee no I haven't had my coffee yet maybe that's the problem all right so anyways what we're doing today is we're going to create a store for episodic and declarative memory and then we're going to do semantic search or vector database search so we're basically just covering the bottom two layers of this now technically we're also introducing the core objective functions or the heroes to comparatives and that is just by virtue of the fact that it is embedded into the prompts you can embed the core objective functions at many many layers at inference time at evaluation time at planning time there's all kinds of places but the point being is that um the core objective functions are literally the first type of cognition that's applied to the data um going up and down the stack which means that their core they're Central to the operation of the thing whatever else it's doing problem solving executive function cognitive control memory consolidation all of that still is above the core objective functions which mean the core objective functions apply to all of that and then finally here's a much more complicated diagram this is kind of what it's going to look like eventually but we're basically just doing the bottom three layers here and we're we're essentially going to be doing just the Nexus today we're not going to be doing any other microservices okay so before we dive off I did also want to ask you to consider if you don't donate to me to to support you know uh my life consider donating to unhcr so um the the unhcr is um uh the un's organization for helping refugees um I've given to unhcr for many many years I started during um actually the the civil war in Syria many years ago because it was just awful and it broke my heart and I was like I want to do something um but like you know I'm just I'm just a dude um it's not like I was going to go stop the war single-handedly so I looked around and I was like okay well you know the it's it's a huge Refugee crisis so how can I help that and I looked around and actually have a friend um an internet friend who uh was in Aid coordination for many years I don't know if he still does that um but anyways I asked him and he said yeah unhcr like they're they're you know every every non-profit organization station has its issues he's like but unhcr is good um because one it is it is accountable it's a global entity but also it has Global reach which also makes it pretty good um so I give to you in HCR every month for more than 10 years now um and uh I certainly don't regret it so given everything going on all over the world uh you know just uh just give give it a thought um yeah all right so moving right along let's dive into pine cone um like I said I haven't used it before I know people that have I've looked at it I know the underlying technology and I said this is this is the way um oh also before we get started the repo for this is Pinecone infinite memory chat bot infinite memory once you see the numbers you will understand what I mean like we're we're about to build a chatbot that has a longer memory than well I'm not going to say than God because that's just too hyperbolic but longer memory than any single human the bass uh uh um like tier for pine cone um is free and I think I could be wrong but I think that they um they said like you get up to five million inferences or five million records so imagine that you have a database a chat bot that remembers the last five million messages that is a long conversation so let's see let's see if we can do this oh and also you go to their home page long-term memory for AI gee that's kind of what we want isn't it all right so I'm not going to bore you to death with how this works we're just going to jump in and use it so I'm gonna go ahead and sign up um here I'll go ahead and pause this for a second okay well it was supposed to ask me um how like how I got how I figured out that I wanted to use Pinecone but um it did not so create your first index all right this will be um this will be uh Raven MVP lowercase okay let's see uh let's see Raven uh MVP uh Dimensions um okay so here's the thing is we need to know um open AI uh not that uh docs dot open a um this is a mess all right documentation because here's what we're going to do we're going to use open AI um their embeddings right here there we go and we need let's see embedding models where is ada02 pages per dollar 3000 text embedding 802 um output Dimensions so max input is 8100 output is 1536. okay so we are going to do 1536 dimensions um let's see lowest latency and highest throughput best storage capacity faster queries let's do we'll do P1 sure whatever uh will be terminated after 14 days create index okay um yep all right so here's our index it's initializing that's cool so I if I recall correctly and I apologize to anyone at Pinecone if this is wrong I think what it's doing is it's actually spinning up an individual container for me on the cloud um yeah because the environment is U.S east one gcp so this tells me that it is running my container on the Google Cloud um yes so and then rather than doing rather than uploading stuff individually um what I'm going to do is block not that um all right we are going to do we're going to go back to where did it go Pinecone dot IO um all right so we're gonna go back to the docs and we're gonna do quick start and also I apologize that this video is a total unmitigated mess but you know what all of you watch it on like 2x speed anyways so you're probably just laughing your butt off all right so let's do a pip install Pinecone client ta-da so tldr you need the Pinecone client in order to run python now that being said a lot of you expressed interest in how do I do this stuff if I don't know the first thing about coding so I'm going to try and do as little coding as possible so we're going to jump over here and use chat GPT I upgraded to chat GPT Pro man is it much faster um I definitely recommend it because one the speed and two it I don't I don't know if it's actually smarter or if it just feels smarter because it's faster um but definitely um chat GPT Pro I think is is totally worth it especially for 20 bucks a month it's like this it saves me so much time and my time is so valuable right it that it's a it's a no-brainer it's definitely worth it okay so what are we trying to achieve here we're trying to get a chat bot that we'll use up to five thousand or five million memories so what I want to do is I want to save every chat message that I do with uh with with this chat bot and uh and I want to recall stuff based on recent conversations so um let's make a Ultra simple chat bot um using uh openai text oops text Ada um O2 embeddings for search ability um we will index each message chat message back and forth and then we will store all messages in a pine cone index I want you to write a python script that will do this for me okay so if you don't know code um that's okay because chat GPT does all you need to do is know the um English language to describe what you want um and so let's see if this works all right it doesn't seem to know some of this stuff yet it's creating the index I don't need it to do that it also doesn't it shows 512 so all you need to do is be able to look at it and say like is this really right okay I'm sorry I don't understand Dave but you see how much faster this is it just spit all this out in a couple seconds and so I'm like this is right I don't know if this is right all right so close but no cigar um text davinci02 okay so it's it's this out of date it doesn't it it doesn't even know about text davincio 3. all right so we're probably going to need to do a little bit of uh cutting and pasting let's say all right so this was the this was the script that I used for um the last long term chat bot memory so basically what we're going to do is we're going to throw all that out because here's what happens with iterative development if you're not familiar with agile basically you get as far as you can this is this is iterative development on an individual level you get as far as you can and then when you get stuck you basically like refactor everything that you've learned and start over um okay so actually my door is open I'm gonna pause it and close the door real quick and also a quick wardrobe change because I was getting too toasty uh imagine that you're super animated and drinking coffee and you get too hot it's getting hot and no I'm not gonna do that I'm not gonna subject you people to that I actually do have a good singing voice it's just I'm super not warmed up and I have awful timing so all right where was I um right pine cone yeah this is close but it's not quite so let's let's let's break this down into the functions that we're going to need um so I've got this function or this script here 172 lines of code we can actually simplify this a lot but we need to keep the stuff that we that we like so I'm going to go ahead and keep my uh completion so this is this is the actual chat function so we're gonna we're I'm going to leave this script as is just so that um I have it for reference uh because if you know me you know that I am uh horrible at just recycling code which sometimes gets me in trouble but whatever whoops nah come back um so we're gonna call this chat two dot pi because that's super creative okay so what this does is it chooses text davinci03 which is the latest and greatest in terms of fine-tuned models uh the temperature is set to zero um because I actually don't like uh entropy injected unless I want it to be injected in most cases a deterministic output is fine because it's just a thinking machine and I achieve what I want with prompt engineering so I am a chatbot named Raven my goals are to reduce so heroin add excuse me word wrap where is word wrap there we go my goals are to reduce suffering increased prosperity and increase understanding I will read the conversation notes recent messages and I'll provide a long verbose uh detailed response hold an end my response with a follow-up or leading question alright so instead we are going to do uh we don't need notes because we're just going to do a super long-term memory um and then we are going to actually yeah here we'll just have the conversation here um uh let's see previous conversation all right that's fine and then we will say um yeah that's fine all right so we update this and basically what I'm going to do is I'm going to populate this with um with what we retrieve from uh uh from Pinecone so we come let's take a look at the repost so the repo I've got pinecone.text and I thought I copied my openai API key I did not um we'll copy this from another repo okay so we got open Ai and then pine cone here I'm just going to shorten this so it's openai.txt so there's these are my these are my keys here I'll I'll do this I'll do uh key underscore so that they stay together repo hygiene is important e underscore so we've got two API keys we're going to be talking to open AI for the large language model and the embedding and then we're going to be talking to Pinecone for storage so we're not really going to be doing any storage locally all right so first things first let's come back here and figure out what we need um let's oops I closed the chat let's go to this one so we need we need the main Loop so if you're not familiar with coding and I do apologize I promise that we would do like let's let's call this low code not no code but low code um while true so pretty much all chat Bots start with a wild true Loop and actually a lot of a lot of programs um start with a wild true Loop so this is basically just an infinite Loop and let's shorten this openai.txt okay so while true what do we do I don't know um I think over here I had yep get the get the user input first that's all good um let's see so then we get the vector so gpt3 embedding did I use I might have I might have already switched to uh Ada oops um text embedding 802 oh I was using it great Okay cool so I've already written this function fantastic so we can cut whoops we don't need the prompt so we can go ahead and copy this function too so we get the embedding um which is great and also some of you ask why I do this here where I I um I do content and code to ASCII ignore errors and then decode this is because for whatever reason some Unicode breaks gpt3 I don't know what it was but I just found out that forcing it to ASCII and then because ASCII is a smaller code base than Unicode and then converting it back forces it into a correct format the gpt3 already accepts so or always accepts um so fix any Unicode errors because there's like there's like Unicode bomb which is uh not bill of materials but uh some something to do with the way that it's encoding um whatever anyways so we get our embedding um and then we come back down here all right so let's do this and then the message oh yeah so user time string Etc Great so that's all fine and then maybe we need the info too because I think Pinecone allows us to save some metadata all right so let's let's do this uh all right and then we will come over to Pinecone documentation nope it's over here quick start all right so pine cone in it we need this guy here environment your environment um let's see no not create index let's come over here import Pinecone and then we also need to set foreign key so this will be open file hindcone dot text and if you didn't catch this I what I did earlier and I didn't show you was I put I got my API key and put it in here so um so there you have it oh actually no I need to update the name so that it is correct key pine cone and then uh e open Ai and then environment I think is going to be this guy is that the environment so API values okay um I'm not sure which environment it could be it could be the index name I don't know usually sometimes what they have is they'll give you like here's the python version of this um but we will we will uh go back to the docs rtfm read the fund manual um all right index.ubsert oh here we go so pine cone um let's see what is environment I don't know not applicable okay I really don't know what this what this is this also uh no both your API key okay just says note your environment all right Pinecone people if you're watching I don't know what you mean by environment because I go to my console and I don't see anything named environment index name oh environment here okay region region okay so for for the it infrastructure parlance this would be called a region not an environment environment is like are you running in a Docker container or on a Linux machine or in VMware but the the cloud region okay got it figured it out all right so basically I need to tell the API talk to this region region figured it out I'm not going to let this go the way of the future so I recently re-watched The Aviator with uh with Leonardo DiCaprio and I I initially watched it in theaters many years ago and I was Ultra disturbed because um the way that he repeats things I used to do that in my head and turns out like that's just a really common feature of OCD and it's because it doesn't feel right and if you know what I mean you know what I mean and that is um basically like it's a it's a sensory processing issue and so something doesn't feel right you have to keep doing it until it does feel right um fortunately I got over that mostly just by one accepting that like okay this is a thing and then I kind of got used to it over time also fixing your diet and sleep really helps with OCD okay quick aside all right we got that figured out let's go back to our documentation okay so we initialize it so this is just initialize so this init thing so Pinecone in it is about the same as just setting our API key okay I think that that's fine yes all right so that's nested correctly I think and then we get down we don't need to create the index we just need to grab an index so let's come back over here so index equals pine cone index and this will be Raven Dash MV I know how to type I promise raven- MVP um and I don't like index I'm going to do VDB Vector database whoops all right so this is our Vector database and then we okay so we do an upsert so we give it a string and then that okay so if we give it a string and then and then a vector if that's I I know that they said that we can do oh wait here we go IDC score oh wait no that's just the query okay um well okay so we'll we'll keep it simple we'll just do the string that's fine so index.upsert or in this case VDB dot upsert so the message string will include the user the time and the message so the that it's all going to be included in the message so that's fine um and but the vector we should actually do the vector later so that the vector includes all of that information I think right or should we only search the the what the user actually put in you know what screw it I'm going to index the entire thing so the vector equals um gpt3 and premature tabbing tab completion Not all men have this problem but if you do have this problem there's nothing to be ashamed of okay um you're getting a little bit more unfiltered Dave lately I hope that's okay some people say like oh you need to be like more humble and laid back and it's like now this is this is just my true self so um I apologize if you don't like it tough all right so time stamp equals this so we get a time stamp so time stamp is a Unix Epoch so it's just a Str it's a it's a it's a number it's a floating Point number we need timestamp to time stamp to date time um so let's grab this function okay all it does is it returns a specifically formatted whatchamacallit English readable time stamp that's fine so let's grab this put this here and then so all right we can get rid of that guy we can get rid of that guy vectorize it save to Pinecone all right now so we've got our message and we've got our Vector so let's go look at the Pinecone documentation and so what we do is we have to upsert and we have a string or well so first it's a list and then within the list there are tuples and the tuples have uh at at index 0 is a string and index two is a vector so this should be pretty straightforward um you know we can actually probably save some time if we just do the upsert at the end so let's do that let's let's let's add our message and Ravens um at the end so that way we don't accidentally pull our most recent messages oh I like that yeah okay so um so let's see this will be um upsert uh actually no we'll just we'll call info info list and so then we will do info dot append and then so we need uh the info is the list container so now all we need to do is add a tuple that has message and vector and so then once we get once we get our chat Bots message we'll append it as well and then we'll just upsert them both at the same time Bingo all right so next thing we do is and this is this is actually good because we will use this Vector to search for Raven's response which means that we won't pull yeah yeah it's order of operations man and if it doesn't make sense sit tight it will in a minute let me do a time check I'm probably just going to take this all the way through we're 30 minutes heck with it I want to get I want to drive this across the Finish Line I don't care if it takes two hours probably won't take two hours and I know that all of your eyes are bleeding already eyes and ears like you're just like Dave shut up write some code whatever okay um all right so now uh search for Relevant messages and generate a response cool so this is the this is where it gets fun not that it wasn't fun already um we need to do a query all right I don't know what top K is what does top k mean in this context um include values the following example and for the top three vectors that are most similar oh okay so top K is just how many similar do you want simple enough all right so we will do um results equals VDB dot query man this is straightforward all right so then Vector equals vector so basically we're going to say whatever whatever it is we just said to Raven get all messages that are most similar and we'll do a top k top top Butterfingers top k equals let's say 15. um so the 15 most relevant messages and then um I don't actually care about the values so that's fine so we'll just do um what does it include values include values equals false I just want the messages don't really care so it should return okay it'll return a dictionary with matches and then matches will be a list and it may or may not have values or it might just be a list of strings okay so results okay so um results matches um so this is this is the this is the list of of stuff so now we need to format it um let's see let's see let's see let's see let's see we're not going to delete anything are we really almost done that's fine all right so if this is if this is a list so let's let's see how I formatted it over here let's go back in time all right so conversation load conversation um generate a response uh fetch declarative memories we're not going to do that memory is equals fetch memories okay we did all that fun stuff and it's just a big giant mess so actually here's what we're gonna do we're gonna have um uh conversation equals um n dot join results Dot um matches and actually wait why oh right hang on so what this returns is it doesn't return the string or does it hang on in the indexer updates a vector with the same ID already present wait this isn't a string this is an ID how do I how do I actually fetch a string let's see if there is something better because if I have to keep track of an i of an ID in my own index I mean it's not the worst thing in the world but it would be slightly less convenient okay so here is some information oh here we go here we go here we go okay yes so I give it an ID and then a vector and then some metadata okay so then if I want to give it that I can filter so you can pull those IDs so ID values so the value is that and then the metadata is something like this so I can set some metadata got it got it got it all right that's straightforward enough I think I guess okay so the message is not this the message is something else um but this is actually fine because now I can set the time stamp time string the speaker and the message itself as the metadata so let me go back and grab this because this is basically so because if you look at this set metadata right so when we when we uh do this all right so here's the upsert so we give it an ID and it looks like it can be alphanumeric I'm going to try a uuid because I don't really care about the ID um but I get maybe I should but I just like using uuids so instead we will use this here so we will just give it an arbitrary uuid4 okay and then so then then there's the vector so it's ID vector and then metadata so the metadata is this guy here that I'm working on um so we'll just call this a payload instead so our payload because this is what we're this is what we're actually going to upload eventually all right so the speaker is user the time is time stamped the vector we don't need the vector in the metadata we do need the message we don't need a uuid and then a Time string so speaker time message time string so that will all be in the metadata and actually let's just go ahead and call this metadata so that we don't hurt our brains later and then metadata all right so now hypothetically maybe we'd actually do need to include values true it should include the metadata on fetch um query so we can use that to filter but can can it return the metadata fetch vectors update vectors list collections describe a collection delete a collection it might be this might not be the way we might have to keep um the the messages locally and all that this is going to do is return us an ID now if we have a uuid that makes it really easy to um metadata let's see all right so we can set the metadata metadata let's see all right all metadata is indexed okay that's interesting that will slow it down in the long run but I kind of don't care here let's go way back up to the top metadata okay without a metadata config okay so it just it just that's setting the metadata config include metadata okay okay here it is here it is this is what I was looking for if we say include metadata this will probably return our metadata I think we'll give it a shot okay all right um so include values include metadata let's see if this works and so if this is the case then results matches so results will be um that was the upsert whereas the query so index dot query here and then wait there was an example of like what was the output what did the output look like I think that was under Quick Start index.query there we go okay so it'll give me matches which is itself a list and then the list will include the ID so that we're going to use a uuid it will give us a score which is the the similarity and then the values but then also it should include metadata hypothetically um I think so that'll have a list and each item in the list will be itself a dictionary and the dictionary should include metadata and the metadata should include a message as well as a time stamp and a few other things this is all very confusing um but with all that said that needs to be in that correct order does it I don't know ah it might be actually simpler just to save to save our stuff locally so what we'll do actually is we'll we'll call we'll um I was I was afraid I kind of I kind of knew that this would be the result um uh let's see unique ID equals string four uh and the reason that I knew this was the thing is because I know that the underlying technology is uh the Facebook AI semantic search which all it does is return an ID um so what we'll do is we'll save the metadata separately um yeah yeah and yeah we will go ahead and save we won't save we won't save the vector because that's a huge that's a huge burden but we will save the the uuid all right so we'll do unique ID that's fine so the metadata this will this will actually be saved as a Json file the same way that we did over here okay so we'll do save Json thank you Nexus and then the file name file name equals we'll do unique ID here actually no we just do dot Json and then we'll use the unique ID for the placeholder okay and then metadata here and we'll remove metadata here so this will this will just uh Pinecone will just serve as instant search and then it'll tell us which uuids to grab later okay cool ah this is a hot mess um all right so we don't need values or metadata all we need is the ID yeah all we need is the ID so it should return a list of dictionaries with IDs when we do the search okay and so then what we do is we need to we need to we need to um recompose the conversation so let's do load conversation and then we'll say results um okay so results should be actually no yeah we'll say uh yeah result should be um uh should be addict with matches um which is a list of dicks um with uh ID okay lowercase this because that is the actual name of the element so that should be what we need there so now we need to do a function def equal no that's not how that works um def what did I do load conversation okay so then results and I know a lot of people say why don't you use vs code and copilot and stuff it's like I hate Ides I particularly hate vs code but also that kind of defeats the point of like showing you how to code also I realize that I am increasingly a liar because this is not a low code experiment let's see if we can get get this to uh to to write it though okay uh let's write a function that um that accepts a results um object from a pine cone query this uh returns a list of IDs which are used for the file names of the um of the objects we are trying to load load from local storage um these files are in a folder called Nexus and they are appended with DOT Json so so now write a very simple python function that accepts results um and then loads then let's see yeah loads the Json files with matching ID file name does that make sense all right let's see what it does let that run yep all right load objects from Nexus object IDs equals results dot IDs I don't think that that's how that works unless maybe it does does results.ids is that part of the payload like dot IDs like that doesn't seem to be that doesn't seem to be part of it so index query ID string optional example yeah so like here's here's a filter it doesn't it doesn't give me an example of the response so pine cone if you're watching it would be helpful if you gave me an example of the response object because I don't know that chat GPT understands this um yeah but the logic here is sound enough because we know that that we know that it's a list of objects so we'll do result equals list and then we'll do um four uh let's see m in results dot matches I think that was the um go back up to Quick Start yep so matches so for for that what we need then is the ID so then we'll have um file name equals m ID plus actually here we'll just do I'll grab my load Json let's see open file save file load Json save Json grab these functions okay this will do info equals load Json and all I need to do is pass it the file path so the file path will be Nexus um and then we'll backfill that dot Json and then this will be M ID and I think that should load the message and the message will have this metadata right so we'll know we'll know the uuid it was in the file name already but now it's a handy dandy object time string message timestamp and user so what now now what we can do is we can actually recall we can recall all the most relevant things and sort it by time okay so info equals load Json we get the we get that information and then I think I already had this function here load convo yep so we load it load it we sort it okay and then we do result dot append info ordered equals sorted result key Lambda D time um yep reverse equals false sort them all chronologically yes that should be good and then so after we load the con convo we need to format it and then recent get last messages okay I don't I don't think that that's the correct way to do it um but so if we look here the message saved has all this so all we need to do is then reconstruct all we need to do is then sorry brains are a little bit scattered so ordered equals this so rather than return ordered all we need to do then is say um message block equals backslash n dot join um oh actually here let's do some list comprehension so then we'll just do messages equals um I message oh that's why my my keyboard is slid over that's why I keep fudging it I was like I'm leaning a little bit all right um iMessage for I in ordered so this is this is what's called a list comprehension which basically just says let's make a simple list instead of a nested list um all right so then we'll do join I messages um dot strip at the end and then return message block and you could just do yeah simplify this return this okay so in theory this returns given the results this returns just the most recent conversation that we had or not most recent uh most relevant conversation that we had with Raven so now we can populate the um the prompt so prompt response we don't need any notes we're just doing infinite memory so prompt equals open file prompt response replace um here we can get rid of all this replace conversation with conversation and so what this is going to do is it's going to jump over here and we're just going to replace this so it will it will be sorted chronologically but it will also only have the most relevant memory uh uh conversation elements so this will go back infinitely far regardless of how long the conversation is it's only going to pull the 15 most recent relevant things so we should actually probably parameterize this um so we'll do like uh uh let's see convo length equals 15 and then we'll do top k equals convo length and so then because we do have a really large window so we can actually probably up this to like 30. um because we have uh unless unless the messages are super long um and also since we're offloading a big chunk of the search it's all fine okay so then we do um we basically have to do the same thing previous generate response vectorized et cetera et cetera so output so this will be Raven's response time stamp times string message yep we get the message and then the vector we're going to do this this way so the vector is that we're going to pick another unique ID do this the same way thank you all right so instead the metadata or the speaker will be Raven the rest will be the same because we've already got that save Json we give it the same unique ID we give it the metadata payload append unique ID and vector so that's all there so now it's searchable and I think the last bit is we just need to give the output oh yeah we did we did save Json so we saved it to the Nexus let's go ahead and make that folder folder Nexus and then print the output and it's that simple and my friends if I'm not mistaken we are ready to test this oh boy this is gonna this will either work or it will explode python chat 2. user hello Raven are you awake uh list of pen takes exactly one argument and two given oh right line 102 append this is supposed to be a tuple I knew that um payload append oh you know what else I forgot to do I forgot to actually do the upsert um so now we'll do VDB dot up search payload hello Raven how are you today hey cool okay so we got a response so let's check okay previous conversation there's nothing here obviously um of any society in order to cool so Raven's already waxing philosophical about the core objective functions yes remember they are very low on the stack that is on purpose um what do you think are the primary causes of suffering in poverty um well uh suffering is intrinsic uh to life according to Buddhism so then what we'll do is once we get a response we will make sure let's see yep there we go we're getting we're getting responses so we know that the search is working all this is good this is good some of the primary causes include inequality all right so Raven is kind of talking to himself I also misspelled previous conversation um right do you think there are any solutions to reducing poverty um actually that's uh kind of your purpose isn't it um you are a chat bot and prototype AGI meant to help us with these goals so let me turn that around how do you think you can help reduce suffering and increase prosperity so let's see what Raven thinks about this now also one thing to keep in mind is because okay so this is a brand new conversation it's super short um let's see yep gives me some stuff let's see do you think there are any other solutions to this so on and so forth so let me show you what's going on in the Nexus so this is the raw data right there we go time string so one thing that that I noticed is that Raven spit out a time string here so that's not exactly what we want so let's see I'll now provide a long detailed response oh right this happened last time because I'm including the time string here so I think what we need to do is I think we actually do need to go back and remove um we need to remove uh yeah I actually did this exact thing last time where the message that I've that I vectorized and saved included all this and it's not supposed to this is only supposed to be there on the output I think um because basically basically what it what chat GPT is doing or not chat GPT um gbd3 is doing is it's noticing the pattern and it's saying oh well I'm supposed to uh regurgitate this pattern ah so that's not correct actually what I did was I added this information um so that so that when Raven is reading it when it's when it's put in Raven can see the time stamps but I think that that is actually just Superfluous information so what I'm going to do is I'm going to duplicate this and then just say message equals a whoops and then we'll do the same thing down here message equals output okay so that's fine all right so suffering and poverty are complex issues that are multifaceted Solutions um blah blah blah this can be done through initiatives such as this okay um Raven do you know what you are let's see what Raven says okay so Raven's basically just talking to himself so that's no good um so if we go back and look at let's look at the last log um oh Raven's not responding to my question because I don't have my thing so this is why Raven is just talking to himself okay so so we need to add we need to we we do need to insert at least my most recent response um okay so we need to go into our prompt and so then we'll do user um and then we'll do message and so then what we need to do is for the replace um let's see output and there we go and then we'll do replace message with um a because that's my user input because otherwise this is why Raven's talking to himself okay hello Raven uh what were we talking about yep we were discussing this we were discussing do you think there are any other Solutions um let's change topic I want to know um I wanna I want to uh discuss what you are do you know what you are Raven and so what I do want to say I'm a chatbot and prototype AGI Okay cool so he remembered when I said that um my primary goal is to provide a platform for people to discuss and understand underlying causes of suffering and poverty to explore potential Solutions I have also designed to provide a safe and secure environment for people to share their thoughts and ideas my capabilities include natural angle of processing machine learning and artificial intelligence um yeah that's that's uh those are some good inferences um uh were actually still exploring um what you are and how to deploy you um so let's see what he says to that so anyways you get the picture it's working there's all a million little bugs to figure out but we just set up and we are using Pinecone as a Nexus service so that's pretty cool uh Raven's final output as a chatbot and prototype AGI I'm designed to reduce suffering and increase Prosperity forgot about the increase understanding um just kind of regurgitating what he said I'm also designer Okay blah blah blah okay so not the smartest thing but we do have a very basic Nexus Service uh I think we'll call it there because this was a raging success
Info
Channel: David Shapiro ~ AI
Views: 37,126
Rating: undefined out of 5
Keywords: ai, artificial intelligence, python, agi, gpt3, gpt 3, gpt-3, artificial cognition, psychology, philosophy, neuroscience, cognitive neuroscience, futurism, humanity, ethics, alignment, control problem
Id: 2xNzB7xq8nk
Channel Id: undefined
Length: 61min 46sec (3706 seconds)
Published: Mon Feb 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.