Machine Learning

Summarized using AI

Empowering the Individual: Rails on AI

Obie Fernandez • September 27, 2024 • Toronto, Canada

The video titled "Empowering the Individual: Rails on AI," presented by Obie Fernandez at Rails World 2024, discusses how integrating AI into Ruby on Rails can significantly enhance a solo developer's productivity and creativity. Obie emphasizes that AI has the potential to elevate individual developers and small teams to unprecedented levels of performance, aligning with the concept of the "One Person Framework."

Key Points Discussed:
- AI's Impact on Development: Obie shares his experience with Ruby and Rails, explaining that AI enhances experimentation and innovation, allowing developers to bring ideas to life without needing extensive teams or funding.
- Practical Tips for Using AI: He outlines four essential steps for AI integration in development:
- Using AI as a more effective search tool than Google or Stack Overflow.
- Employing AI code completion tools, like GitHub Copilot, to streamline coding tasks.
- Collaborating with AI to implement specific app features and functionalities.
- Using AI to replace entire components in subsystems to reduce code complexity.
- Concrete Patterns: Obie introduces patterns for effectively utilizing AI in coding, such as:
- Narrow the Path: Focuses AI's reasoning on specific tasks by defining clear parameters, avoiding excess ambiguity.
- Multitude of Workers: Decomposes workflows into discrete, AI-driven components that act like microservices, allowing for natural language interactions between them.
- Real-World Application: The talk provides insights from his personal projects, including the development of "Olympia," an AI-driven tool aimed at providing tailored responses and functionalities for users. He shares examples of prompts that effectively direct the AI's capabilities to fulfill user requests.
- Practical Magic: Obie illustrates several successful implementations where he utilized AI to ease coding and workflow challenges, including a scenario where an AI assistant effectively managed account configurations based on user commands.
- Conclusion: The main takeaway from the presentation is the transformative potential of AI for individual developers, enabling them to write less code while increasing productivity and innovation. The discussion motivates developers to explore integrating AI into their Rails projects to harness these benefits fully.

Empowering the Individual: Rails on AI
Obie Fernandez • September 27, 2024 • Toronto, Canada

Integrating AI with Ruby on Rails can transform a solo developer's workflow into an incredibly potent force, capable of competing at an unprecedented scale, bringing the dream of the "One Person Framework" even closer. At #RailsWorld Obie Fernandez shared a roadmap for integrating AI tools and techniques into your projects, insights into the potential pitfalls and best practices, and inspiration to explore the boundaries of what a single developer or a small team can achieve with the right tools.

#rails #AI #rubyonrails

Thank you Shopify for sponsoring the editing and post-production of these videos. Check out insights from the Engineering team at: https://shopify.engineering/

Stay tuned: all 2024 Rails World videos will be subtitled in Japanese and Brazilian Portuguese soon thanks to our sponsor Happy Scribe, a transcription service built on Rails. https://www.happyscribe.com/

Rails World 2024

00:00:12.519 guess what a conference what a conference so okay I think now you can
00:00:18.520 hear me how's everyone doing I want to hear you charge me up come
00:00:25.279 on so someone told me I'm giving a second to last keynote uh which I'm not in the same category as Aaron sorry uh
00:00:33.040 but I'm looking forward to that anyway empowering the individual rails on AI uh you know one of the things that is
00:00:39.680 really amazing over the years over the decades I can say now about rails is the way that it has allowed me to
00:00:46.559 indulge uh my desire to experiment and make uh cool stuff by myself because
00:00:53.120 often that's the only way you can do it right you can't you have ideas and you can't afford to hire a team or or raise
00:00:58.640 funding for certain things and I find that one of the most beautiful amazing exciting things about
00:01:06.799 uh the way that AI is developing is that it amplifies that kind of potential and it it it 10 times uh amplifies it when
00:01:15.400 it comes to rails and ways that are amazing so first of all as more people are coming in uh let me just go to the
00:01:21.400 next slide and for those of you that are not familiar with me uh the realsway is probably what I'm most famous for in
00:01:27.520 this community uh but I do have uh almost 30 years next year it be 30 years as a
00:01:33.360 professional software developer and I did full stack Java from 1995 to 2004 2004 was when I fell in love with
00:01:41.000 Ruby and uh I was probably one of the first people in the world to be doing uh to consult with Ruby uh and rails at
00:01:48.320 thoughtworks and that was a significant experience uh that led me to write the rails way and found hashrocket and some
00:01:55.320 of my old friends at hashrocket are still here in the audience so hi to them did a brief AI related project in 2019
00:02:03.119 and that's what piqu my interest and I wanted to make sure to mention that you know a lot of things I'm going to talk
00:02:08.640 to you about are directly extracted from my personal experience I'm not a fan of vaporware or handwavy stuff that doesn't
00:02:16.840 really make sense in a practical context I want to make sure that I give you today ideas and practical inspiration
00:02:24.480 and tips and tricks that you can take home to actually use on your current projects that will are you as an
00:02:30.560 individual so uh what everything I'm going to show you started out actually
00:02:36.519 right before last year's rails comp I was really excited about access to the open AI API and I wanted to make a
00:02:44.000 contribution uh using that API and I created this open source Library called magma chat I announced it at rails comp
00:02:50.680 and gave a lightning talk on it and as a result of creating magma chat I was able
00:02:56.800 to create a bot for my uh for my partner uh Victoria who I was dating at the time
00:03:02.680 and she was working as a media partner for a conference series and she had a
00:03:08.799 copywriter so much better okay you know I fancy myself a standup comic and I've
00:03:15.519 tried standup comedy so I actually like this a lot better I don't like this thing it's
00:03:22.319 bothersome but all right so um yeah as a result of creating magma
00:03:28.640 chat uh you know I was talking to uh Victoria and I said hey let me create you an AI copywriter for your job and
00:03:34.120 she started using it all the time and when I saw that she was using it all the time uh I said hey do you want to start
00:03:39.760 a company together and we started this company called Olympia my uh the purpose
00:03:45.080 of this talk is not to Hype Olympia but I took a lot of the code that I'm going to show you out of Olympia so therefore
00:03:50.360 I just want to make you aware of where it's coming from uh in the case of
00:03:56.879 um what um I was doing with Olympia is to create you know these humanized Bots
00:04:04.599 and these humanized Bots give you um advice in the way that chat gbt would
00:04:09.680 give you advice but in particular roles so for instance um a recent conversation
00:04:15.760 I had with my par programmer Mike was you know asking him how can I use an rspec stub in my rails console I didn't
00:04:21.519 remember how to do that and he gave me that advice so anyway I I've been super excited about the work that I'm doing in
00:04:28.039 Olympia and I gave a talk talk about why I thought AI was so disruptive and
00:04:33.639 exciting uh and it was called the biggest wave of all uh Sin City Ruby which is a great conference shout out to
00:04:39.919 Jason you should definitely go to Sin City Ruby if you can uh but anyway I gave this talk uh and it was all about
00:04:46.360 Ai and my friend Tom Rossy uh at the end and Tom might be here as well he said
00:04:52.320 this seems really cool but where do I get started and I said wow um I think
00:04:59.320 that this is really worth uh investing some time into helping to educate and
00:05:05.080 disseminate the information that I've been learning over the last year of doing Olympia so anyway how can AI
00:05:11.479 Empower you as a rails developer there's really four steps to the enlightenment
00:05:17.000 of that so the first one probably all of you are doing to some extent or another
00:05:22.479 which is uh and I think dhh even mentioned it which is that chat gbt uh and CLA is
00:05:30.600 a better Google or stack Overflow it's easier to you know to get answers uh by asking these tools and most of the time
00:05:36.560 they give you good advice so that's step one I'm not going to spend time uh talking about this uh because it's kind
00:05:42.479 of obvious the second one is to use AI code completion in your editor IDE to code
00:05:49.199 faster and I'm guessing I I could ask for show let's ask for show hands raise
00:05:54.319 your hand if you use co-pilot or some sort of code completion and as expected almost everyone in the audience puts
00:05:59.880 your hand up right so that's the second step now the third step I think probably
00:06:06.479 less of you are using but it's to use AI to implement features that by asking the AI to code those features for you so
00:06:14.240 this would involve more than just code completion inside of a file this involves uh what could be termed agentic
00:06:20.599 behavior in the sense that you're collaborating with the AI and saying hey give me a a particular uh new uh you in
00:06:30.680 my rails uh app and it it goes ahead and creates it for you the fourth one and
00:06:35.800 actually what the bulk of the talk is about that I'm most excited about is using AI to replace entire components in
00:06:41.160 subsystems so that you can write less code and writing less code is really
00:06:46.960 really where you start to reap the kind of Whirlwind benefits that AI can offer and I think is the most
00:06:53.720 revolutionary uh part of what's coming in this AI Revolution so let let's get
00:06:59.840 to it I'm going to talk about these two things real briefly use AI to help you write code is number one and use AI in
00:07:06.199 your code so that you can write less code someone actually gave away the first part of my talk so I made it
00:07:12.360 really short now as a result uh thanks Peter rusika use cursor AI problem solved uh he's right step one use cursor
00:07:22.319 sorry GitHub oh they're sponsors I shouldn't do that right uh it's copil
00:07:27.759 and worth $20 a month um cursor gives you the ability to do code completion it's very good at it uh
00:07:35.440 you can do chat driven changes and refactoring uh you know by asking it to for instance
00:07:41.199 exract uh this actually solves something that I've been wanting ever since I left
00:07:48.039 uh the Java world and stopped using jetbrains uh products is that I missed
00:07:53.080 those refactorings you know I miss the ability to say extract the variable or pull this up a level or things like that
00:07:58.840 I have that again and and I know that Ruby mind does some of those things but you know this works
00:08:06.319 better um when you're giving those instructions you can give follow-up
00:08:11.560 instructions uh you can chat about your code base some of this is just I'm going to Breeze through it so I can get to the
00:08:16.800 good stuff I only found out about this a few days ago actually I was talking to a friend of mine about my talk and he told
00:08:23.759 me oh have you seen that cursor can create files for you I didn't realize cursor had a gantic behavior if you hit
00:08:29.120 command I I'm figuring some of you may not have figured this out already as well uh you can ask it to implement
00:08:35.039 features on your behalf so I don't know if it's very visible right here but I tried this a few days ago I asked it to
00:08:41.120 uh add an action and it did so step one use cursor okay now I
00:08:49.080 really want to get to the meat of this talk which is learning AI patterns learning how to use AI components in
00:08:54.560 your code so that you can reduce the amount of code that you have to write and you can actually offload a lot of uh
00:09:01.560 business logic and uh workflow and process Automation and orchestration to AI so uh I'm going to plug my book here
00:09:09.519 if you don't have my book already I know a lot of you do but this is my new book it's a 500 page book full of uh patterns
00:09:16.279 for how to do what I'm describing in this talk it goes into explicit detail not only about the big picture items
00:09:22.440 around architecture but also about concrete patterns and uh you know actual
00:09:27.560 code samples and like I said for the that code these ideas have been
00:09:32.839 extracted from working code in Olympia Olympia is an app that has a user base
00:09:38.360 that uses it all the time we are a small successful cash flow positive company that is using this every day day in day
00:09:46.360 out what I'm about to show you I will show you magic this is Practical Magic okay so first of all let me talk a
00:09:52.560 little bit about the abstract patterns abstract patterns as I describe
00:09:57.920 them are ways to understand how the AI fits into your code conceptually
00:10:03.680 so when you're describing to yourself in your inner voice you know okay well what can I do with AI or when you're
00:10:09.920 describing it to your boss uh you know what you want to do with AI uh you need
00:10:15.880 to be able to describe it in terms of the uh the architecture of the system how they will fit in uh those abstract
00:10:23.079 patterns I know that they might be a little bit difficult to read you know there's too many here but they include
00:10:28.360 things like narrowing the path which is the way that I describe reducing the latent space or or basically focusing
00:10:35.639 the AI on the task at hand uh there's also retrieval augmented generation which a lot of you are probably familiar
00:10:41.959 with because it's one of the fundamental techniques for how you provide grounded information to the AI but it also
00:10:49.200 includes things that maybe you haven't heard about like for instance self-healing data it's the ability to
00:10:55.519 automatically detect diagnose and correct anomal ities in the data that flows through your system uh and if you
00:11:03.839 want to get even more bleeding edge with some of this stuff there's even generative UI which is where you're no
00:11:09.920 longer explicitly designing every single screen and interaction of your user
00:11:15.600 experience you're actually setting a framework and guidelines that is then
00:11:21.279 interpreted by the AI in order to create a personalized user experience on the
00:11:26.519 Fly uh this can be affected by the profile of your user what their
00:11:32.680 previous activity has been on your system or what they're trying to do what Their what their actions reveal about
00:11:39.279 their intentions and the AI adjust the user experience on the fly so the the
00:11:44.320 one I want to talk to you about today there's two of them um the first one is
00:11:49.519 called narrow the path and the idea of narrowing the path is something that's very very fundamental to understand as
00:11:55.680 kind of one of the foundational uh pieces of knowledge for doing prompt engineering Okay the reason is that the
00:12:02.560 latent space uh which is the the multi the high dimensional space of the knowledge that
00:12:10.519 is captured in the especially in these Frontier models uh that have billions and now are you know getting into the
00:12:16.680 trillions of parameters that they are trained with is such a vastly
00:12:22.360 incomprehensible large amount of data that an AI has access to on the Fly that
00:12:29.600 at any given moment that you're trying to get the AI to do something with your
00:12:34.720 prompt engineering as they say it is subject to a lot of difficulties that
00:12:40.839 are not immediately apparent so those difficulties include things like information
00:12:46.199 overload is probably the most uh you know obvious one if you think about it
00:12:51.839 for any given thing that you ask the AI to do it has like almost the entire history of the internet of what people
00:12:57.600 have said about that thing and to do it so if you don't give it like temporal
00:13:02.880 constraints about what time or uh scope constraints or what even what domain you're operating or talking about then
00:13:09.839 it can get overloaded and get confused there's contextual ambiguity the way that you speak to the AI can cause it uh
00:13:17.399 because of that vast lat in space to not know exactly what you mean and because AIS are trained to be
00:13:24.199 helpful that they interpret that helpful to just go ahead and give you an answer instead of saying I don't no or can you
00:13:30.680 please clarify there's ways around that but that's not immediately obvious so when I think about narrowing the path
00:13:37.160 part of narrowing the path is making sure that my context is as narrow as possible I mentioned temporal
00:13:43.920 inconsistencies and domain specific nuances but if you want to have a
00:13:49.240 takeaway for this narrowing the path means focusing the model's reasoning on a specific subset of
00:13:55.759 possibilities so when you're asking the AI to do do something or generate a piece of content in your prompt
00:14:02.199 engineering you want to specifically think about okay out of all the different ways that this could be
00:14:08.720 interpreted you know and then you literally maybe even list them out and
00:14:13.800 then you go how can I how can I narrow this path uh so that it doesn't go off of
00:14:19.519 it here's an example of the abstract pattern being implemented with a
00:14:25.120 concrete pattern so the concrete pattern is called Ro assignment and in the role assignment and some of you may have done
00:14:30.959 stuff like this uh in your own projects if you're experimenting with it uh here are two different role assignments the
00:14:37.199 first one says you are a teacher giving lessons to a curious 8-year-old child explain how attention in lmm llms works
00:14:44.639 this path has been narrowed in that a lot of terms and terminology that an 8-year-old child would not understand
00:14:52.279 are eliminated from the space of possibilities okay uh that is significantly different than telling the
00:14:58.000 AI that they are an NLP or natural language processing Professor giving a lecture to compai uh
00:15:04.199 postgrads right okay so narrow the path was the first abstract pattern the second one I
00:15:09.839 want to talk to you about is called multitude of workers this one is really significant was a breakthrough for me in
00:15:15.079 terms of thinking about how to design uh and use AI inside of my rails
00:15:21.560 applications okay the idea is that you can decompose your workflows uh you
00:15:27.880 could substitute business l in there into collaborating Almost Human discreete components it's almost like
00:15:35.399 having uh little humanlike microservices that live inside of your code okay they
00:15:41.680 don't have to live outside they're not hosted on some external system these are code modules inside of your code okay
00:15:49.720 you ask these code modules these discrete AI components your multitude of workers if you will uh to perform
00:15:57.240 specific tasks or uh make complex decisions in ways that you would have
00:16:03.720 otherwise had to code imper uh imperatively or using just normal programming
00:16:09.440 methods uh so the reason I got to this
00:16:15.399 realistically you know I I I worked at thought Works had the honor of being uh mentored by people like Martin Fowler
00:16:21.839 and Fred George especially who originate a lot of the thinking around microservices to begin with uh but also
00:16:27.720 the first o programming Lang language that I use was small talk and in small talk we think about interactions between
00:16:33.079 objects as messages that are being kind of spoken between these objects um with the case of discrete AI
00:16:40.279 components and a multitude of workers approach you can actually speak you know between these
00:16:47.040 objects in ways that are pretty much plain language English right so in my
00:16:52.240 example here one component might tell another one user 7482 hasn't logged in
00:16:57.319 recently the component would reply let me look at their activity history it goes and looks at it and then based on
00:17:03.040 that it says okay I'll send them an email about our latest new feature as a way to maybe generate some engagement
00:17:09.319 okay that's the kind of thing I'm talking about seems a little Loosey Goosey maybe handwavy and if you're skeptical I understand uh but there's
00:17:16.559 benefits that we'll get into very soon another foundation for this is actually behavior-driven development in the sense
00:17:23.160 that what we were trying to do 10 and 20 years ago uh when bdd was like a really really hot thing some of you may
00:17:29.840 remember is to describe in plain language what we wanted our system to do
00:17:35.600 and in fact at hashrocket one of the things that we pioneered was actually uh making the basis of our requirements and
00:17:42.720 even in some cases our contract negotiation these definitions done in
00:17:47.840 cucumber using bdd techniques so I was immersed in this and and help drive this
00:17:53.559 forward so I'm kind you know I feel like those of us that had the uh you know the
00:17:58.880 pleasure and sometimes the pain realistically of doing this stuff uh you know are kind of positioned to to think
00:18:06.039 about it I'm very influenced and I owe a debt of gratitude to to ASAC and Stephen Baker this was at rubycon 2005 so a
00:18:12.600 little bit of history and trivia this is where arpec was started literally the
00:18:17.720 first lines of code for what became arpec and also some of the lines of code that later became cucumber were written
00:18:24.000 at Ruby comp 2005 which is also where I took this picture that I posted on Twitter yesterday hi Toby thanks for
00:18:31.240 coming to my talk um I don't know if David is here as well but yeah fun times
00:18:36.919 okay so I don't know if magic triggers anyone in this room it certainly triggers other people out there in the
00:18:43.080 world that have not been indoctrinated properly thanks uh for saying that in your
00:18:48.400 keynote today I do think we need to indoctrinate people more by the way but yeah sorry don't get triggered I'm going
00:18:54.840 to show you some magic okay I mentioned Olympia before and I mentioned that some of these techniques are directly extracted from Olympia in Olympia uh one
00:19:02.840 of the things that you can do is to add additional Bots to your account if you don't already have them uh in this case
00:19:08.960 what I'm showing here is that chandel is an optional bot that has not been added to the account and um I'm going to show
00:19:16.640 you the way that I implement the addition of a bot to a user's account okay that's done with an account manager
00:19:24.320 class the account manager class is one of these multitude of workers that I use to collaborate inside of the Olympia
00:19:30.360 code base and the prompt that drives that account manager class at Olympia
00:19:36.039 reads like this I'm not going to read the whole thing I'll just read the first paragraph you're an intelligent account
00:19:41.240 manager for Olympia the user will request changes to their account and you will process those changes by invoking
00:19:46.880 one or more of the functions provided escalate to human support rep if you encounter any problems okay this is
00:19:53.880 almost the entire prompt there's a few other details that I left out for clarity
00:19:59.000 here are the functions that are available to the account manager as tools that they can use to do their job
00:20:06.159 when they're processing changes to the account since one of the main things that I ask it to do is to handle adding
00:20:11.960 Bots to accounts they have an ADB config to account they can add a new line item
00:20:17.280 to the subscription they can notify the account owner and they can call a method is completed I actually left one out by
00:20:24.240 mistake they can also contact customer support they can literally like cause a
00:20:29.360 ticket to be filed okay um there's no AI magic going on in the implementation of
00:20:35.240 these functions the implementation of these functions is just normal uh in
00:20:40.280 this case sorry shitty rails code uh that does the thing that it says that it
00:20:45.320 does in this case adding bot config to account um interestingly enough I rolled this out to production and a week
00:20:52.240 later uh JP our one of our great customer support reps contacted me in slack and said hey we have a situation
00:20:59.440 with a user who had scheduled their account for cancellation their account is not canell yet but it's not in an
00:21:05.320 active State and they added a bought to their account and it worked and I don't think that's correct this was just a missing requirement this kind of thing
00:21:12.320 happens all the time right so I said yeah that doesn't seem right I think we should probably not let people who are
00:21:17.720 scheduled to be canceled add new things to their account so he said great do you want me to add a noce story for it and I said no
00:21:24.799 I think I already got it and what I had done was basically go in and write this new line do not allow the user to change
00:21:30.000 their account or add a new AI assistant unless their account subscription is active I don't have time to get into
00:21:36.039 like the actual implementation of how the account manager interacts with the rest of the system but I want to make it clear that
00:21:43.520 this actually did work so I did some ad hoc testing admittedly to see what would
00:21:49.240 happen with this new change to the prompt and what happened was that the account manager sent me a notification
00:21:55.320 saying hey I'm sorry your account is not active State therefore I cannot add this
00:22:00.480 spot to your account um I don't know does this seem magical to
00:22:06.600 anyone it seemed pretty magical to me this is not for everyone maybe you don't want to make patients lives or you know
00:22:13.200 jet planes flying through the air dependent on this sort of thing but you know one of the times I mentioned this
00:22:18.600 before someone said hey aren't you afraid this will hallucinate a bad result or send you know something that
00:22:24.200 do something that's not to do the truth is with narrowing the path and giving you
00:22:30.919 know explicit instructions this works I think about as well as a human would work this is pretty basic stuff that
00:22:37.000 you're asking it to do and it seems to be well within the the reasoning capabilities of the state-of-the-art models and in fact one of the reasons
00:22:45.159 that this works and one of the reasons I think the material in this talk is important is because of the
00:22:50.799 architectural approach if you took a naive approach to doing this sort of thing you might lard your entire
00:22:57.559 component of with literally all of the business rules of your of your
00:23:03.159 business uh or so much information that it gets overwhelmed or confused and does
00:23:08.320 the wrong thing and then you might go hey this approach doesn't work it sucks Obie's lying blah blah blah no that's
00:23:14.279 not the case the case is just that you haven't made that component small enough right when you do these narrowly scoped
00:23:21.080 uh techniques they they actually work so anyway that's my multitude of workers
00:23:26.400 pattern there's applications I think in account management which I just showed you but also e-commerce I know a lot of
00:23:32.120 you work in e-commerce like half the conference is Shopify right so okay uh product
00:23:38.640 recommendations fraud detection sentiment analysis Etc there's Healthcare applications as well I wanted
00:23:45.000 to mention before I end the talk some of the concrete patterns so so you see that these can actually be kind of fun uh
00:23:51.360 there's 28 concrete patterns in the book um I'm looking at them real quick I mean
00:23:57.520 I I with with a couple of exceptions they're all extracted from working code it's very very crucially important to me
00:24:04.360 that patterns are extracted from real working code right um a lot of the patterns have to do with prompt
00:24:11.080 engineering uh for instance structured IO this is a pattern that describes how
00:24:18.000 you provide your input data to the llm uh AI in a way that predisposes it to be
00:24:24.919 able to understand as data as opposed to just a conversation Hey Joe like how you
00:24:30.360 doing today okay now this this grounds it Narrows the path okay to use the
00:24:36.840 example for the AI that the way that you want to interact with it now is as a
00:24:42.799 machine that is you're going to give it data and in fact one of my predictions that I made is that XML will make a
00:24:49.120 comeback because it's it's actually super super trivial to parse uh XML
00:24:54.240 using regular Expressions uh and you can do things like this so in this case um
00:25:00.440 an example taken from the book uh I give it a description and I'm wanting to get name size price and color from the
00:25:06.760 product description the fact that I have already put this into XML format means
00:25:11.840 that it's going to very very quickly and to say oh he wants XML back I don't have to do a lot of extra prompting and
00:25:18.080 prompt engineering to get this result another example concrete pattern
00:25:23.240 that's used in prompt engineering is the ventriloquist pattern which I think is really really fun okay
00:25:28.880 um it almost feels like a hack a lot of this stuff almost feels like a hack but you know it actually works really really
00:25:34.720 well the idea when using the ventriloquist pattern is that you plan the desired outcome from the ai's
00:25:40.039 response but the way that you narrow the path is by speaking on behalf of the AI
00:25:45.320 you're using it like a puppet in a way you're providing part of the interaction
00:25:50.600 that you have in that conversational uh cycle with the AI and I'll show you an example of that so this
00:25:57.760 is a real uh class from Olympia that in the case that the search uh that the user did or
00:26:05.120 caused to happen more precisely did not return any results I
00:26:10.840 want to produce some alternate keywords which I will now use to do a search again and try to bring back results so
00:26:17.039 if I call your attention I don't think I have a laser here unfortunately but if I call your attention to the middle uh
00:26:23.399 method there uh which is where I assembled a transcript
00:26:28.919 the system prompt which is the directive that kind of sets the tone for what is going on here is you are a powerful
00:26:34.200 search web search engine so here I'm doing a role assignment okay um I'm
00:26:40.520 providing the input from the user and the input from the user was their original question that they asked that
00:26:47.159 they didn't get a result from now I'm not going to tell in the
00:26:52.960 promp all this I'm not going to say hey you know the user us didn't get the
00:26:59.039 results I'm actually going to simulate and that's why I call it vilous the user asked a question the
00:27:05.080 assistant said searching no results found this is congruent with the fact that it's a search engine and then I'm
00:27:10.559 providing the prompt uh and the prompt says matching the original language of the question generate three alternate
00:27:16.399 keywords that might produce better results the reason I did it this way was not just to be clever not just because
00:27:21.799 it was a hack or an interesting example for the book I literally did this because I was struggling with the other
00:27:27.039 approach with the more just kind of direct approach of like hey um generate alternate keywords for this terms right
00:27:34.880 like I was doing that and it just wasn't performing very well and then one day I decided hey oh I could use this ventriloquist kind of thing and it
00:27:41.200 actually worked really well it understood much much better what I was trying to
00:27:48.399 do um some of the other concrete PL patterns have to do with uh how you
00:27:54.320 create this discrete components um an example of a discrete component would be a predicate now if you've done Ruby long
00:28:01.000 enough you're an expert in Ruby you know that the question mark methods are called predicates because they are uh
00:28:07.840 return booleans right true or false result and a predicate pattern as far as I'm concerned with AI is one in which
00:28:16.000 you ask the AI question that get that is designed to give you a yes or no answer or a true or false answer one of the
00:28:22.480 side benefits being that you can ask to for it to explain its reasoning okay so here's an example
00:28:29.600 um I'm not going to read you this whole thing but at the beginning of this prompt uh you give a transcript of a
00:28:35.760 conversation uh and the idea uh for this particular predit class is to analyze
00:28:41.200 what the user is talking about and then answer the question does the transcript contain enough context for the assistant
00:28:48.480 to be able to answer the user question without making assumptions if you think about the fact
00:28:54.399 that Olympia is you know kind of like a chat GPT and we do a you know we have long-term memory and we search that
00:29:00.080 long-term memory in order to provide uh proper answers to the prompts this is a
00:29:05.120 very useful thing for us to know whether there's enough context in the the conversation as it's gone so far in
00:29:11.559 order to do that search so here's another concrete example just going to go through it real quickly an API facade
00:29:18.399 is something that's actually almost directly taken from Gregor Hop's classic uh patterns of Enterprise Integration
00:29:24.279 but when we do it as an discrete AI component what that API facade pattern lets us do is to go from a generalized
00:29:32.159 AI assistant that knows that it can do certain capabilities like interact with
00:29:37.200 the user's email but it doesn't lard the context of that General assistant with
00:29:42.840 all the specific implementation details of how an API works in the case of Olympia Olympia assistant can help you
00:29:49.760 with your Gmail but if I put all of the Gmail capabilities or even a subset of them of the API that's available into
00:29:57.200 the main conversation Loop it would get the that assistant confused very quickly so we use the API facade to basically
00:30:05.559 set up that bridge to give the main assistant the general assistant more capabilities than it would
00:30:12.200 otherwise anyway a lot of the examples that I've shed here today uh are based
00:30:17.799 on my own little Library called Ray that's Ruby AI extensions um you can
00:30:23.320 find it at our Olympia GitHub and everything I've shown you today is described in a lot of detail in
00:30:30.799 my book patterns of application development using AI which I'm super excited uh to say that Gregor hopy who I
00:30:37.080 mentioned a minute ago is writing the forward for and as soon as he sends it to me which should be any day now uh
00:30:43.159 we're going to get this published in hard copy as well so if you want it today it is available and pretty much
00:30:48.360 done on leanpub or you can wait for it to come out on uh all the platforms but anyway I hope you get a lot of use from
00:30:54.440 this and I hope you enjoy the rest of the conference and I'll be avail able if you have any questions thank you very
00:31:00.240 much
Explore all talks recorded at Rails World 2024
+17