background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Why abstractions are useful (storing openai conversations into a db)"

input logo icon
Video tags
|

Video tags

web development
programming
coding
code
learn to code
tutorial
software engineering
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:01
around with this text Adventure RPG that
00:00:03
uses open Ai and also something called
00:00:05
Lang chain to basically keep track of
00:00:07
the conversation I'm having with the AI
00:00:09
system so that when I ask it questions
00:00:12
in the future it can kind of go back and
00:00:13
check what has already been discussed
00:00:15
what is the actual scenario for this
00:00:18
adventure that we're going on and when I
00:00:20
first started building this I was using
00:00:21
something called buffer memory to store
00:00:23
the information inside of the memory of
00:00:26
the computer right the issue with that
00:00:27
is that when I stop the program it
00:00:30
clears Out All the known memory right so
00:00:32
you don't know what your character is
00:00:34
you don't know where you are in the
00:00:35
actual dungeon you don't know how many
00:00:36
hit points you have it all kind of just
00:00:38
gets wiped away right and that makes
00:00:39
sense so I've been looking into a way to
00:00:40
basically store the history or the
00:00:42
memory inside an external database so
00:00:44
that when I kick this off again it's
00:00:46
going to continue off where we left off
00:00:48
so with that background information all
00:00:49
being discussed the reason I'm making
00:00:52
this video is I want to discuss
00:00:53
something that's very important when it
00:00:54
comes to programming and that is
00:00:55
interfaces you are using interfaces all
00:00:58
the time we declare functions you need
00:00:59
to clear arguments in the return values
00:01:01
of those functions and you may not know
00:01:04
about what the interface is if you're a
00:01:05
beginner interfaces are a great way to
00:01:08
allow you to extend and swap out
00:01:10
functionality just by using like
00:01:12
abstract classes and other types of
00:01:14
approaches right so let me show you what
00:01:15
I did so what do I mean by that right
00:01:17
previously we're using buffer memory and
00:01:19
I'm taking this variable and passing it
00:01:20
to this memory argument of conversation
00:01:23
chain right if you hover over this
00:01:25
you'll notice that memory has to be a
00:01:28
base memory type of class so what this
00:01:31
allows us to do is that whenever you
00:01:33
declare a new class as long as it
00:01:35
extends
00:01:36
some existing functionality like an
00:01:39
abstract class or something like that
00:01:40
and if you keep diving down the
00:01:43
extension chain so like you'll notice
00:01:44
that this one extends base memory what
00:01:46
this allows you to do is you can start
00:01:48
declaring your own classes and because
00:01:50
they match the expecting interface of
00:01:53
this memory property everything will
00:01:55
just work right so in order to extend
00:01:58
instead of using the in memory buffer
00:02:00
memory I can use my own external memory
00:02:02
all I need to do is basically make my
00:02:05
own generic chat memory and notice that
00:02:08
this is just a class that extends base
00:02:09
chat memory and when you extend an
00:02:12
abstract class most of your Ides are
00:02:14
going to give you like suggestions of to
00:02:16
like as to like what you need to
00:02:17
implement for example if I comment all
00:02:18
this out you'll notice that this is red
00:02:20
saying that you were not implementing
00:02:22
the correct abstract members so if I go
00:02:24
down here and say Quick Fix notice that
00:02:27
it'll add all the methods that I need to
00:02:29
basically get started to enable this to
00:02:32
store memory in an external database
00:02:34
right so I added those required methods
00:02:37
and basically when the black box which
00:02:40
is this conversation chain decides that
00:02:42
it needs to either load or write the
00:02:45
conversation history it's going to call
00:02:47
one of my two methods here it's either
00:02:48
going to call load memory variables or
00:02:51
it's going to call Save context and
00:02:53
because I follow the interface it's very
00:02:55
easy to kind of like extend the
00:02:57
functionality just by taking these
00:02:58
inputs writing them to a database or
00:03:00
taking these inputs and fetching them
00:03:02
from a database again this video is more
00:03:04
for like beginners so if you're kind of
00:03:05
advanced you already know about Audrey
00:03:06
Dorney programming and Abstract classes
00:03:08
and interfaces this is going to be like
00:03:09
a boring video but overall the point I'm
00:03:12
trying to make is that like all I needed
00:03:13
to do was make a new class that extends
00:03:15
that abstract class and then I pass it
00:03:18
my own methods for writing and loading
00:03:20
history from my own type of data stores
00:03:22
so in this case I am storing and
00:03:24
retrieving the history data in a
00:03:25
third-party service called convex which
00:03:28
is basically a backend as a service and
00:03:29
it also gives you the database without
00:03:31
having to set that up as well and notice
00:03:33
that when at some point conversation
00:03:35
chain decides to load the history all
00:03:39
I'm saying is query my database call
00:03:41
this load history method and then join
00:03:44
all of the conversation histories into a
00:03:47
single string and return that right so
00:03:49
all this thing needs to do is just
00:03:50
return a string of the previous chat
00:03:52
conversations together and this thing
00:03:55
can figure out how to like do what it
00:03:57
needs to do all right same thing with
00:03:58
writing history events I get an input
00:04:00
and a response and I just need to write
00:04:02
that somewhere to doesn't matter what
00:04:03
database I write that to this could be a
00:04:05
file store this could be somewhere else
00:04:06
but this thing was written in a good way
00:04:08
where like it depends on a nice
00:04:10
interface that allows you to kind of
00:04:11
swap that out whenever you need to so
00:04:13
let me just run this real quick I'm
00:04:15
gonna say mpm Run start
00:04:17
okay and so that's gonna basically you
00:04:19
know set me up with like you are a
00:04:20
warrior you're going to go into a
00:04:23
haunted place and then it's asking are
00:04:25
we ready to begin I'm going to say yes
00:04:27
we are ready like this all right a group
00:04:29
of Undead creatures approaches you with
00:04:31
their eyes glowing with the Eerie light
00:04:32
they raise their swords really 20-sided
00:04:34
die to determine your attack roll let's
00:04:35
just go and roll one real quick I'll do
00:04:37
a nine okay and it kind of tells you
00:04:39
that you hurt one of the undead
00:04:41
creatures and then they also strike me
00:04:42
the point I'm going to show here is that
00:04:44
uh if you go up to your database now
00:04:46
notice that that history has been stored
00:04:49
inside a table here where I have the
00:04:51
chronological order of all the inputs
00:04:54
and the responses from open Ai and
00:04:57
behind the scenes when lingchain decides
00:04:59
that it needs to like tack on another
00:05:01
call it's just using this database under
00:05:04
the hood right all I had to do is extend
00:05:05
the interface and I'm like good to go so
00:05:07
I guess what I'm trying to say is that
00:05:09
it is important to understand how
00:05:10
implicit and explicit interfaces work in
00:05:13
software I mean you use them all the
00:05:15
time whether you know about them or not
00:05:16
and using something like typescript or
00:05:18
Java or strongly typed static languages
00:05:20
allows you to have an explicit interface
00:05:23
to find so that people can come by and
00:05:25
easily extend your lower level Library
00:05:27
if they need to right so the better you
00:05:29
define your interface the better your
00:05:32
abstraction could potentially be alright
00:05:34
so now that I kind of got that out of
00:05:35
the way I do want to talk about some of
00:05:36
the hurdles I'm running into with this
00:05:38
project one thing is every time that you
00:05:40
basically you know roll a dice or send
00:05:42
in a command this has to take all of the
00:05:45
previous conversation history and it
00:05:47
sends it the open AI so this
00:05:48
continuously gets larger and larger and
00:05:50
larger as the game goes on and at some
00:05:52
point after like five or six responses
00:05:55
that you type in the token length gets
00:05:57
about a thousand now I think open AI
00:05:59
with this turbo model charges like 0.00
00:06:02
one five
00:06:04
Cent
00:06:05
per 1000 tokens so basically this is
00:06:08
going to start adding up right you're
00:06:09
going to keep on getting charged as your
00:06:10
gain gets longer and longer and also
00:06:12
you're going to hit limitations there's
00:06:13
only so many input tokens that you can
00:06:15
provide these models some some are set
00:06:17
to 4 000 some are 8 000 some have a much
00:06:20
higher threshold but they have different
00:06:22
costs associated with them right so one
00:06:24
thing I started adding into this game
00:06:25
was basically after you have X amount of
00:06:28
prompts that get run what we're going to
00:06:30
do is we basically summarize the state
00:06:32
of the game and we have openai basically
00:06:35
print out that summary somewhere let me
00:06:36
just go ahead and roll um again let me
00:06:38
roll 20. at some point it should
00:06:40
summarize and it should print out how
00:06:42
much help I have what's in my inventory
00:06:45
um here it is okay so all right so what
00:06:47
I'm doing after like five or six prompts
00:06:49
is I'm telling open AI to please
00:06:50
summarize the game State including the
00:06:53
goals the current location player Health
00:06:55
items into a single paragraph so we can
00:06:57
easily continue at a later time please
00:06:58
use the least amount of words as
00:06:59
possible okay so what this does is it
00:07:01
basically prints out the state it says
00:07:04
the player is currently engaged in a
00:07:06
battle with Undead creatures they have
00:07:07
successfully landed hits on two of the
00:07:09
creatures dealing six points of damage
00:07:10
each the player has also managed to
00:07:11
block two attacks take no damage there
00:07:14
are still two Undead creatures remaining
00:07:15
the player's current location is unknown
00:07:17
and their health and inventory are not
00:07:19
specified again why I'm doing all this
00:07:20
is so that if someone were to decide to
00:07:22
close the game and come back it's going
00:07:24
to load in the chronological history
00:07:25
it's going to hopefully read in one of
00:07:27
these summarize game States and open AI
00:07:30
is going to be able to basically resume
00:07:32
where you left off right so it's only
00:07:34
going to grab the past like five prompts
00:07:36
so these things will be emitted so if
00:07:38
there's anything that's super critical
00:07:39
that was omitted here and that's not
00:07:41
included in your summary then you're
00:07:42
going to actually like have a weird
00:07:43
experience they kind of have to play
00:07:45
around with like how much memory you
00:07:47
want to give this thing so in this case
00:07:49
I give it five but maybe you want to
00:07:50
give it 10 or something again the higher
00:07:53
the memory the more this will cost to
00:07:55
keep playing what I do is in the game
00:07:57
first initializes I check
00:07:59
is this the first time we've played if
00:08:01
not then we ask openai remind me where
00:08:04
we left off okay and if you notice here
00:08:06
it's going to use that history that's
00:08:07
stored in the database and it's going to
00:08:09
say you're currently engaged in battle
00:08:10
with Undead creatures it basically just
00:08:12
printed out the very last summary but um
00:08:15
this could potentially there could be
00:08:17
more stuff above here that like needs to
00:08:18
be summarized as well so I'm going to go
00:08:20
ahead and say attack the
00:08:23
creatures so now there's goblins
00:08:25
attacking me those games are getting
00:08:26
more intense and what I did also do is
00:08:28
down here I have a math.random
00:08:30
and if it's less than 0.15 then I also
00:08:35
include this at the end of my prom
00:08:36
saying please include a random battle
00:08:38
encounter right so I think that's why
00:08:41
I'm getting attacked by goblins now is
00:08:43
because I added some difficulty to say
00:08:45
like add in some more encounters
00:08:48
um so now I'm fighting Undead creatures
00:08:50
and goblins so that kind of sucks anyway
00:08:52
I've been having a little bit of fun
00:08:53
with this just elevating my knowledge
00:08:54
with the open AI um I do plan to
00:08:56
hopefully make an actual interface for
00:08:58
this like a nexjs application UI that
00:09:02
kind of shows maybe images of the game
00:09:04
as we're playing and then also the
00:09:06
inventory I could use Dolly to generate
00:09:09
images for the icons that are coming in
00:09:11
I think that would be really cool as
00:09:13
well yeah that's all I got for you guys
00:09:15
have a good day and happy coding

Description:

📘 T3 Stack Tutorial: https://1017897100294.gumroad.com/l/jipjfm 🤖 SaaS I'm Building: https://icongeneratorai.com/ ✂️ Background Cutter: https://www.backgroundcutter.com/ 💬 Discord: https://discord.com/invite/4kGbBaa 🔔 Newsletter: https://webdevcody.com// 📁 GitHub: https://github.com/webdevcody 📺 Twitch: https://www.twitch.tv/webdevcody 🤖 Website: https://webdevcody.com 🐦 Twitter: https://twitter.com/webdevcody

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Why abstractions are useful (storing openai conversations into a db)" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Why abstractions are useful (storing openai conversations into a db)" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Why abstractions are useful (storing openai conversations into a db)" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Why abstractions are useful (storing openai conversations into a db)" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Why abstractions are useful (storing openai conversations into a db)"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Why abstractions are useful (storing openai conversations into a db)"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.